13

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

Dan
  • 351
  • 1
  • 3
  • 16
  • Please share the contents of your config/webpacker.yml – rossta Dec 07 '19 at 19:57
  • Just added it to original post Thanks – Dan Dec 09 '19 at 16:40
  • 4
    In development, if Rails thinks the webpack-dev-server is running, it won't trigger compilation. See if there's a process still hanging around listening on 3035 (your dev server port). On my Mac, I would run `lsof -nP -i4TCP:3035 | grep LISTEN`. – rossta Dec 10 '19 at 14:27
  • Unfortunately it doesn't appear to be running in the background. This one has me puzzled. I remember maybe about 1-2 weeks ago this was still working. I would start my Rails server and then at the first browser request, I would see the webpack compiling. This is not happening anymore. Really strange – Dan Dec 11 '19 at 16:40

6 Answers6

20

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...

EdSF
  • 11,753
  • 6
  • 42
  • 83
  • 1
    Thank you! It was super-frustrating hitting this issue right out of the gate. As a note, I just added a `console.log()` statement to my `app/javascript/packs/application.js` file and did what you said. Worked great! – Topher Fangio Jun 10 '21 at 16:38
5

If webpacker stops responding to changes in application.scss or application.js, run this command in terminal:

rails webpacker:install
Dipen Chauhan
  • 99
  • 1
  • 4
  • this works like a charm for me, also as I use vue, I have to run this command to: rails webpacker:install:vue – Yamit Dec 20 '21 at 20:45
2

So, I actually ran into this today and after reading this question and doing some additional debugging, I realized the Rails Webpacker was failing because I had another project already running Webpacker and that confused the Rails version.

Shutting down the other Webpacker and restarting the Rails server immediately fixed the issue.

Topher Fangio
  • 20,372
  • 15
  • 61
  • 94
0

This drove me nuts when trying to stimulus reflex. This worked for me (although then had another Stimiuls Reflex issue with ActionCable connection is not open! thereafter which was progress.

  1. In terminal execute rails dev:cache which will likely disable caching
  2. Run your rails server
  3. Thereafter re-run rails dev:cache in terminal (after shutting rails server).

In environments/development.rb the relevent config is:

  config.action_controller.perform_caching = true
  config.action_controller.enable_fragment_cache_logging = true

  config.cache_store = :memory_store
  config.public_file_server.headers = {
    'Cache-Control' => "public, max-age=#{2.days.to_i}",
  }
user324044
  • 11
  • 1
0

My case was that I changed my version of node using nvm. When everything stopped compiling, I forgot that switching my version simply uninstalled yarn which is normal, because I'm using another node/npm image and since yarn was installed globally by npm... So:

  1. Run bin/rails webpacker:install, it will say: "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/ Exiting!"
  2. Reinstall yarn using npm i -g yarn
  3. Run your belove bin/rails s command, and you're done

Note: you'll see again [Webpacker] doing its job in your terminal ✅

Sid
  • 81
  • 2
  • 4
0

I had an isse with webpacker compilation not running in the test environment on a project I hadnt touch in a while. bundle update webpacker solved the issue. Weirdly, reverting to the old Gemfile.lock also works now so I dont know exactly what the issue was.

Arctodus
  • 5,743
  • 3
  • 32
  • 44