webpacker: Can't find packs using Capybara/RSpec

Ruby 2.3.1 Rails 5.1.3 Webpacker 3.0.2

I’m using Webkit as my JS driver. I can find the packs while in prod and dev but cannot get my React components to render while running tests.

I have this in my rails_helper.rb and it generates the correct files. config.before(:suite) do # compile front-end Webpacker.compile end

Manifest file: { "application.js": "/assets/packs-test/application-1b884d2f94460a1a42f1.js" }

Output from save_and_open_page <script src="/assets/packs-test/application-1b884d2f94460a1a42f1.js"></script>

My manifest file looks good as well and it pointing in the right files. Do I have to serve these files up with a different process to get them to render?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 29 (18 by maintainers)

Commits related to this issue

Most upvoted comments

I solved this issue in Rails 5.2 rc1 by setting this variable in test.rb:

  # Configure public file server for tests with Cache-Control for performance.
  config.public_file_server.enabled = true

Thanks, everyone for keeping this thread updated. We have added an info task to show version info, thanks to @ytbryan :

bundle exec rails webpacker:info

Will make a new release today.

I solved this issue in Rails 5.2 rc1 by setting this variable in test.rb:

  # Configure public file server for tests with Cache-Control for performance.
  config.public_file_server.enabled = true

this instantly fixed my issue with React components included via react-rails gem not displaying in RSpec tests (js: true) using Capybara/Selenium.

I had the same error mentioned in https://github.com/rails/webpacker/issues/998#issuecomment-375597197 but it was because I needed to add the following to Codeship setup commands:

nvm install 8.4.0
yarn install

I have the same problem locally after deleting the public/packs-test folder.

I use

➜ gem --version
2.7.6

➜ bundle --version
Bundler version 1.16.1

➜ rails -v
Rails 5.1.5

➜ bin/webpack
/Users/holger/.rbenv/versions/2.4.3/lib/ruby/site_ruby/2.4.0/bundler/rubygems_integration.rb:458:in `block in replace_bin_path': can't find executable webpack for gem webpacker (Gem::Exception)
	from /Users/holger/.rbenv/versions/2.4.3/lib/ruby/site_ruby/2.4.0/bundler/rubygems_integration.rb:489:in `block in replace_bin_path'
	from bin/webpack:17:in `<main>'

Error in test

    # Webpacker::Manifest::MissingEntryError:
     #   Webpacker can't find app.js in /Users/holger/projects/clients/edeka/edk-old/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 added config.public_file_server.enabled = true in config/environments/test.rb but it did not change a thing. How could I proceed here?

edit Also happens with Rails Version 5.2.0.rc1 from branch 5-2-stable.

edit 2 Perhaps this is old news, but if I downgrade webpacker to 3.2.2 it works again. It did not work with version 3.3.1 or 3.3.0.

edit 3 OR RTFM => https://github.com/rails/webpacker/blob/master/CHANGELOG.md#breaking-changes bundle exec rails webpacker:binstubs

Now everything works for me again. Sorry again if this was old news for you.