webpacker: Can't find packs when running Rspec
Ruby 2.3.7 Rails 4.2.10 Webpacker 4.0.0.pre.pre.2
File config/webpacker.yml:
# 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
- .module.sass
- .module.scss
- .module.css
- .png
- .svg
- .gif
- .jpeg
- .jpg
- .hbs
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
staging:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
production:
<<: *default
# Production depends on precompilation of packs prior to booting for performance.
compile: false
# Cache manifest.json for performance
cache_manifest: true
File config/webpack/test.js:
process.env.NODE_ENV = process.env.NODE_ENV || 'development'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()
Portion of config/environments/test.rb:
config.serve_static_files = true
When I run:
bundle exec rspec spec/controllers/admin/links_controller_spec.rb
I see:
Failure/Error: = javascript_pack_tag "webpack-runtime"
ActionView::Template::Error:
Webpacker can't find webpack-runtime.js in /Users/sharang/Data/work/gumroad/web/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:
{
}
The problem is that pubic/packs-test
is not generated at all when the test is run.
When I run the test like this the problem goes away:
RAILS_ENV=test bundle exec rake webpacker:compile && bundle exec rspec spec/controllers/admin/links_controller_spec.rb
It seems like the auto-compilation is not happening in my case. How do I debug this? Thanks!
Note: I read through the closed issues where this problem was discussed but those didn’t help me.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 15 (7 by maintainers)
Commits related to this issue
- Manually compile assets Manually compiling assets due to compilation issue with request specs. https://github.com/rails/webpacker/issues/1695#issuecomment-424272859 — committed to NickSchimek/basic_rights by NickSchimek 5 years ago
- Remove public/assets public/packs public/packs-test Removed the files and ran rails tmp:clear. Also reverted the last commit so that webpacker:compile is not explicitely ran. This is being done due t... — committed to NickSchimek/basic_rights by NickSchimek 5 years ago
I know this is closed, but my scenario was not listed here as far as I can see and it was pretty difficult to determine.
As with many others here, I was running
RAILS_ENV=test rspec
and it kept yelling at me because there was nopacks-test
directory. Without considering it for way too long, I finally adjusted my.env.test
file and removed theRAILS_ENV=
from it. Then it worked. As far as I knew command line env vars should override .env files, so this was perplexing to me.Obviously, this was not expected, so I didn’t even consider it. However, there is a caveat when using the Dotenv gem, you can load .env files via
overload
vsload
, which will override any existing environment variables set, example: `Dotenv.overload(“.env.#{Rails.env}”).This resulted in the
RAILS_ENV
being set to an empty string (as it was set in the.env.test
file) and webpacker was defaulting to the production environment. By removingRAILS_ENV=
from my.env.test
file it resolved the issue.What really confused me was that when I ran
RAILS_ENV=test bundle exec rails webpacker:compile
the output was…So, it is still saying that it is outputting to
packs-test
, but it really isn’t. 😦Hey! Just wanted to chime in. In some cases it can happen that you maybe ran
rails webpacker:compile
locally and some files ended up inpublic/packs/
that shouldn’t be there and might reference code that doesn’t exist anymore.So what I can recommend if you are facing this issue to just clean out most temporary files, for example
public/packs-test/
is ok to have around I think, butpacks/
shouldn’t be there I believe.I was having the same issue, just deleting the
public/packs-test
and rebuild solved the issue 👍I’m closing it because we ended up doing this:
https://github.com/rails/webpacker/issues/1695#issuecomment-424272859.
@sturdynut This helped me 6 months later. Thank you!
I encountered the same issue on docker environment. Turns out if you set
NODE_ENV=development
while running rspec, it will lazy compile, but whenNODE_ENV=test
it wont.I wanted to share that I had been struggling with the exact same problem in an older project I migrated to Webpacker and discovered that my
bin/spring
file that was initially created by Rails was different than the one in a newer project (in which I don’t experience this problem). Updating that binstub fixed the exact same problem I was having (though I’m not quite sure why).The more recent and working
bin/spring
binstub looks likes:…whereas the older one that caused Webpacker not to lazy compile test packs when running
bin/rspec
looks like this:Edit: here is my
bundle exec rails webpacker:info
: