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
- followed instructions from https://github.com/rails/webpacker/issues/1494 — committed to dostaglou/HeroMaker by dostaglou 5 years ago
- travis test after implementing fix from https://github.com/rails/webpacker/issues/1494\#issuecomment-388305305 — committed to theresadreamteam/theresa by indisaurusrex 4 years ago
It is fixed this time.
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 withwebpack@^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?
@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
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:
I still have this issue, it created a directory
packs
inpublic
. There is nopublic/packs-test
.This is not an old app. It is created with Rails
5.2.0.rc1
, and we just upgraded it to5.2.0
. I ranbundle exec rails webpacker:binstubs
and it said: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:
spring stop
rails s
./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.
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?