When I run rails s -e production I get a 500 internal server error along with the following error caused by placing this code <%= javascript_pack_tag 'hello-world-bundle' %> in my head tag.
ActionView::Template::Error (Webpacker can't find hello-world-bundle.js in /Users/janedoe/Projects/Rails/myapp/public/packs/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:
{
}
):
@heavenlypeach in production the assets aren't generated when they are requested like dev and test, you have to use rake assets:precompile.
@jacortinas I ran rake assets:precompile and got the following error:
ActionController::RoutingError (No route matches [GET] "/packs/hello-world-bundle-8d452ed8d5646d08fbc8.js"):
ActionController::RoutingError (No route matches [GET] "/assets/application-ea8ca43729dabd837f81720aa2306d5344b0c1930e9d7f1677532fa5c24072bd.js"):
ActionController::RoutingError (No route matches [GET] "/assets/application-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css"):
Normally I don't run rake assets:precompile and instead just set config.assets.compile = true in my production environment. Doing it that way removes the routing errors for application.js and application.css but my hello-world-bundle file is still getting a routing error.
@jacortinas
Solved finding hello-world-bundle running rails server in production.
By default static assets in the public folder are not served in production I just had to make sure that this line config.public_file_server.enabled is set to true.
So I started my server like this RAILS_ENV=production RAILS_SERVE_STATIC_FILES=yes rails s -p 3000.
*Another issue I have found related to the javascript_pack_tag *
When running feature specs on circleci i get the following error:
ActionView::Template::Error (Webpacker can't find hello-world-bundle.js in /Users/janedoe/Projects/Rails/version_17/myapp/public/packs/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:
{
}
):
Solved
The above issue was a circleci config problem. circleci by default was using node 4.2.x and i needed to set the node to version 6 or later. Once I set the node version in circle.yml file, my features tests on circleci passed.
# circle.yml
machine:
node:
version: 8.5.0
@heavenlypeach Glad you figured it out yourself. Thanks for sharing solutions
In "config/environments/production.rb":
config.public_file_server.enabled = true
Delete "public/assets" and "public/pack"
And run:
RAILS_ENV=production bundle exec rake assets:precompile
@heavenlypeach Thanks!
My fix was running this line inside mina deployed current dir 'RAILS_ENV=production bundle exec rake assets:precompile'
Did not fix it for me :/
For me RAILS_ENV=production bundle exec rake assets:precompile does not work on heroku.
It gives me message
RAILS_ENV=production bundle exec rake assets:precompile environment is not defined in config/webpacker.yml, falling back to production environment
Most helpful comment
@jacortinas
Solved finding hello-world-bundle running rails server in production.
By default static assets in the public folder are not served in production I just had to make sure that this line
config.public_file_server.enabledis set to true.So I started my server like this
RAILS_ENV=production RAILS_SERVE_STATIC_FILES=yes rails s -p 3000.