ruby-on-railswebpacker

Rails 6 server just stopped compiling webpack


I have a really weird thing happening.

I was working on this project on my development environment and when I used to start the Rails server,

It would compile webpack on the first browser request.

Now, all the sudden, this is not happening, causing all the javascript and style to fail and the app is not rendered properly.

The Rails server console does not even show the [Webpacker] Compiling… line

If I start the webpack-dev-server myself, it works. But for some reason the rails server has just stopped doing it on its own. I have changed the line webpack_compile_output: false to true in webpacker.yml but the rails server still doesn't show anything that has to do with Webpack.

It's really strange. I haven't added any gems or updated any versions of node or webpack. I did update Git globally on my machine from version 1.9 to version 2.24 but that's about it.

Any ideas?

Update: (As Requested, here is the content of my config/wenpacker.yml

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_root_path: public
  public_output_path: packs
  cache_path: tmp/cache/webpacker
  check_yarn_integrity: false
  webpack_compile_output: true

  # Additional paths webpack should lookup modules
  # ['app/assets', 'engine/foo/app/assets']
  resolved_paths: []

  # Reload manifest.json on all requests so we reload latest compiled packs
  cache_manifest: false

  # Extract and emit a css file
  extract_css: false

  static_assets_extensions:
    - .jpg
    - .jpeg
    - .png
    - .gif
    - .tiff
    - .ico
    - .svg
    - .eot
    - .otf
    - .ttf
    - .woff
    - .woff2

  extensions:
    - .mjs
    - .js
    - .sass
    - .scss
    - .css
    - .module.sass
    - .module.scss
    - .module.css
    - .png
    - .svg
    - .gif
    - .jpeg
    - .jpg

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
  check_yarn_integrity: false
   # Reference: https://webpack.js.org/configuration/dev-server/
  dev_server:
    https: false
    host: localhost
    port: 3035
    public: localhost:3035
    hmr: false
    # Inline should be set to true if using HMR
    inline: false
    overlay: true
    compress: true
    disable_host_check: true
    use_local_ip: false
    quiet: false

    headers:
      'Access-Control-Allow-Origin': '*'
    watch_options:
      ignored: '**/node_modules/**'


test:
  <<: *default
  compile: true

  # Compile test packs to a separate directory
  public_output_path: packs-test

production:
  <<: *default

  # Production depends on precompilation of packs prior to booting for performance.
  compile: false

  # Extract and emit a css file
  extract_css: true

  # Cache manifest.json for performance
  cache_manifest: true


Solution

  • Experiencing this as well. Typically when running rails s you'll see something like this:

    Started GET "/react_test/hello" for ::1 at 2020-05-15 16:54:29 -0700
    
    Processing by ReactTestController#hello as HTML
      Rendering react_test/hello.html.erb within layouts/application
    
    [Webpacker] Everything's up-to-date. Nothing to do
    

    If you make a change to a js (or css/scss) that are part of your webpack resources:

    Processing by ReactTestController#hello as HTML
      Rendering react_test/hello.html.erb within layouts/application
    [Webpacker] Compiling...
    [Webpacker] Compiled all packs in /Users/foo/public/packs
    [Webpacker] Hash: 1ea802b336ed3c771c61
    Version: webpack 4.43.0
    Time: 4844ms
    
    ... truncated for brevity (a list of assets, size, etc)
    

    At some point, all of this stops - and you'll "have" to run both rails s and ./bin/webpack-dev-server manually. So far, what I've noticed is that this is triggered when you run webpack-dev-server - e.g. when updating config/webpacker.yml - it does say it on that file itself in a note:

    # Note: You must restart bin/webpack-dev-server for changes to take effect


    Try this workaround:

    1. Stop Rails server and webpack-dev-server
    2. Make some (temporary) change to your /app/javascript/packs/application.js file
      • e.g. comment out an import: //import 'bootstrap'
    3. Restart rails s (only, not webpack-dev-server)
    4. This will error out - because it's missing what was commented out (in this example bootstrap
    5. Undo/uncomment the temporary change
    6. Reload the page - hopefully, it should be good (Webpack compiles, etc).

    I think (guess) it's some caching/sync issue that is "fixed/(reset?)" by making some change to application.js

    Hth...