webpacker: Webpacker doesn’t compile files in packs-test for test env

My environments:

  • Ruby 2.5.1p57
  • Rails 5.2.0
  • Webpacker: 3.5.3
  • Node: v8.11.1
  • Yarn: 1.6.0
  • Rspec 3.7.1

When I ran a spec/request test locally, I got an error:

     Failure/Error: <%= stylesheet_pack_tag 'application', media: 'all' %>
     
     ActionView::Template::Error:
       Webpacker can’t find application.css in <APP_PATH>/public/packs-test/manifest.json. Possible causes:
       1. You want to set webpacker.yml value of compile to true for your environment
          unless you are using the `webpack -w` or the webpack-dev-server.
       2. webpack has not yet re-run to reflect updates.
       3. You have misconfigured Webpacker's config/webpacker.yml file.
       4. Your webpack configuration is not creating a manifest.
       Your manifest contains:
       {
       }

I checked the possible causes it noticed one by one.

Here is my config/webpacker.yml, and I think it’s OK.

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

default: &default
  source_path: app/javascript
  source_entry_path: packs
  public_output_path: packs
  cache_path: tmp/cache/webpacker

  # 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

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

development:
  <<: *default
  compile: true

  # 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: true
    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

  # Cache manifest.json for performance
  cache_manifest: true

As it said Webpacker can’t find application.css in public/packs-test/manifest.json, I tried to find this file, but I didn’t even have public/packs-test directory.

I tried to search the information for this issue, and I had a look in #194. Then I noticed something interesting.

When I ran RAILS_ENV=test bundle exec rails webpacker:compile, it said:

Webpacker is installed 🎉 🍰
Using <APP_PATH>/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in <APP_PATH>/public/packs-test

However, it didn’t compile files to public/packs-test, but to /public/packs instead. Then I tried RAILS_ENV=test NODE_ENV=test bundle exec rails webpacker:compile and got the same result.

I moved files created in packs to packs-test, then my spec passed.

Is there anything wrong with my configuartion?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 30
  • Comments: 33 (10 by maintainers)

Commits related to this issue

Most upvoted comments

It is fixed this time.

➜ rm -rf bin/webpack*

➜ RAILS_ENV=test bundle exec rails webpacker:compile
webpack binstubs not found.
Have you run rails webpacker:install ?
Make sure the bin directory or binstubs are not included in .gitignore
Exiting!

➜ rails webpacker:install
    conflict  config/webpacker.yml
Overwrite <APP_PATH>/config/webpacker.yml? (enter "h" for help) [Ynaqdh] n
        skip  config/webpacker.yml
Copying webpack core config
       exist  config/webpack
    conflict  config/webpack/development.js
Overwrite <APP_PATH>/config/webpack/development.js? (enter "h" for help) [Ynaqdh] n
        skip  config/webpack/development.js
   identical  config/webpack/environment.js
    conflict  config/webpack/production.js
Overwrite <APP_PATH>/config/webpack/production.js? (enter "h" for help) [Ynaqdh] n
        skip  config/webpack/production.js
    conflict  config/webpack/test.js
Overwrite <APP_PATH>/config/webpack/test.js? (enter "h" for help) [Ynaqdh] n
        skip  config/webpack/test.js
Copying .postcssrc.yml to app root directory
   identical  .postcssrc.yml
Copying .babelrc to app root directory
   identical  .babelrc
Creating JavaScript app source directory
       exist  app/javascript
    conflict  app/javascript/packs/application.js
Overwrite <APP_PATH>/app/javascript/packs/application.js? (enter "h" for help) [Ynaqdh] n
        skip  app/javascript/packs/application.js
       apply  ~/.rvm/gems/ruby-2.5.1/gems/webpacker-3.5.3/lib/install/binstubs.rb
  Copying binstubs
       exist    bin
      create    bin/webpack
      create    bin/webpack-dev-server
Adding configurations
      append  .gitignore
Installing all JavaScript dependencies
         run  yarn add @rails/webpacker@3.5 --tilde from "."
yarn add v1.6.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning " > bootstrap@4.0.0" has unmet peer dependency "jquery@1.9.1 - 3".
warning " > bootstrap@4.0.0" has unmet peer dependency "popper.js@^1.12.9".
warning " > webpack-dev-server@2.11.1" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
[4/4] 📃  Building fresh packages...
success Saved lockfile.
success Saved 22 new dependencies.
…
…
…
You need to allow webpack-dev-server host as allowed origin for connect-src.
This can be done in Rails 5.2+ for development environment in the CSP initializer
config/initializers/content_security_policy.rb with a snippet like this:
policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
Webpacker successfully installed 🎉 🍰

➜  RAILS_ENV=test bundle exec rails webpacker:compile
Webpacker is installed 🎉 🍰
Using <APP_PATH>/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in <APP_PATH>/public/packs-test

Now I have public/packs-test directory with files compiled in it.

According to the change in yarn.lock, @rails/webpacker@^3.2.1 was replaced with ”@rails/webpacker@3.5”, webpack@^3.10.0 was replaced with webpack@^3.11.0.

Could you please make a new app and see if you reproduce this issue? Also, what version of webpacker you have in package.json and Gemfile? Could you please update both to latest version?

yarn add @rails/webpacker
bundle update webpacker

@hegwin Configuration looks correct to me. Could you please do? rm -rf public/packs*/ and then run the compilation task again RAILS_ENV=test bundle exec rails webpacker:compile`. Seems to compile fine for me.

BTW, is this an old app? Have you updated the binstubs? bundle exec rails webpacker:binstubs

After the best part of a day scratching around on this same issue, RAILS_ENV=test bundle exec rails webpacker:compile just solved it for me.

Great 👍 glad it’s fixed

It’s strange though that it says it has compiled the packs in packs-test but the files aren’t there.

Bonjour à tous, j’ai rencontré aussi la même problème, mais j’ai réussi à la résoudre en faisant la commande suivante. rails webpacker:install

Nobody’s mentioned this yet, but the rails defaults seem to send test log output to log/test.log. Notably, webpack may be putting some enormously helpful information there.

In our CI environment this behaviour obscured a completely unexpected problem, which was made visible by adding

  config.logger = Logger.new(STDOUT)

to config/environments/test.rb

Ideally webpacker’s “possible causes” list would direct people to look at the actual output from webpack, wherever that may be.

Hi @gauravtiwari Thank you.

I followed your steps:

➜ rm -rf public/packs*/

➜ RAILS_ENV=test bundle exec rails webpacker:compile
Webpacker is installed 🎉 🍰
Using /Users/xiao.wang/Workspace/rails_projects/sesame_credit/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in <APP_PATH>/public/packs-test

I still have this issue, it created a directory packs in public. There is no public/packs-test.

This is not an old app. It is created with Rails 5.2.0.rc1, and we just upgraded it to 5.2.0. I ran bundle exec rails webpacker:binstubs and it said:

Copying binstubs
       exist  bin
   identical  bin/webpack
   identical  bin/webpack-dev-server

For anyone interested, after following the instructions outlined here: https://github.com/rails/webpacker/issues/1494#issuecomment-387983677 things still didn’t work, but curiously, when I ran:

  1. spring stop
  2. rails s
  3. ./bin/webpack-dev-server

Everything magically worked. No idea why spring stop did the job.

found this resolve via stackoverflow and boy am I glad about it.

webPacker error

Additionally, once I removed line #10 (which auto installed) from my ‘application.html.erb’ file ran: localhost:3000/home/index and Eureka! up again. lol for now anyway.

Cheers to research and resolutions.

Never mind, I’ve found my problem in some of the JS config another dev wrote 😄

To other people that may come across this - check if you’re setting environment.config.output anywhere in your JS config!

Yep, nothing working here either. Everything is output to public/packs - but public/packs/manifest.json refers to /packs-test which of course doesn’t exist so the files aren’t found 😕

Curious if anybody else has this problem with Rails after working with React? I started following a React curriculum yesterday and can’t remember what exactly I changed. Today I woke up to work on my Rails app and now the webpacker is broken…could these be related or is the npm webpack an entirely different entity?