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?
@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
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
@hegwin You could remove the existing binstubs rm -rf bin/webpack* and then re-run the compilation command. See if that makes any difference :) (anyway ignore this one)
It's strange though that it says it has compiled the packs in packs-test but the files aren't there.
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
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/[email protected] --tilde from "."
yarn add v1.6.0
[1/4] 🔍 Resolving packages...
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
warning " > [email protected]" has unmet peer dependency "[email protected] - 3".
warning " > [email protected]" has unmet peer dependency "popper.js@^1.12.9".
warning " > [email protected]" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
warning "@rails/webpacker > [email protected]" 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/[email protected]”, webpack@^3.10.0 was replaced with webpack@^3.11.0.
Great 👍 glad it's fixed
Thank you for your help!
For some reason I ran into the same issue this morning; rm -rf bin/webpack* fixed it for me. Thank you both!
Hey guys! You helped me a lot. Especially @hegwin post about upgrading versions.
I've upgraded @rail/webpacker and webpack and everything works as before.
I've also recently run into the same issue and removing and re-installing webpack fixed things for me
None of the above seems to be working for me. :/
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 :/
@sevenseacat Could you please paste your webpacker.yml?
Never mind, I've found my problem in some of the JS config another dev wrote :D
To other people that may come across this - check if you're setting environment.config.output anywhere in your JS config!
This seems to be working fine now. Can someone else confirm?
(Webpacker 3.5.5)
@ernsheong I think this issue can be closed. I ran into the problem when trying to run my tests on CodeShip and following the above allowed it to work for me also.
I did the following and couldn't get it to work: rails webpacker:install rbenv: yarn: command not found Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
I did yarn install and update with brew which installs yarn 1.12.3, then i try rails webpacker:install i get rbenv: yarn: command not found
try rake db:migrate and keep getting the rbenv: yarn: command not found
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.
This is still happening for me with 4.0.0.rc8. All the suggestions above are not helpful (except for manually renaming public/packs to public/packs-test)