I've just upgraded my Rails app from 5.1.6 to 5.2 and took the chance to also upgrade Webpacker from 2.0 to 3.4.3.
Now, when I push the app to Heroku I get the following error (vendor.js is one the files in /app/javascript/packs
and his called by javascript_pack_tag 'vendor'
in my application.html.erb template):
ActionView::Template::Error (Webpacker can't find vendor.js in /app/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:
{
}
):
And Indeed, when I examine the content of /public
I can see that the /packs
directory supposed to contains my assets is missing.
I can see that during the build phase on Heroku, assets are precompiled:
Running: rake assets:precompile
yarn install v1.5.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.1.2: The platform "linux" is incompatible with this module.
info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.1.3: The platform "linux" is incompatible with this module.
info "fsevents@1.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
warning " > coffee-loader@0.8.0" has unmet peer dependency "coffeescript@>= 1.8.x".
[4/4] Building fresh packages...
Done in 36.65s.
Webpacker is installed
Using /tmp/build_d6c1dd8314f746d28a2469f2a01ec4ed/config/webpacker.yml file for setting up webpack paths
Compiling…
Compiled all packs in /tmp/build_d6c1dd8314f746d28a2469f2a01ec4ed/public/packs
Asset precompilation completed (119.53s)
Cleaning assets
Running: rake assets:clean
My /config/webpacker.yml
file is the following
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:
- .jsx
- .js
- .sass
- .scss
- .css
- .module.sass
- .module.scss
- .module.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
If I change compile: false
to compile: true
in production:
, compilation works but without minification and gzipping.
My /webpack/production.js
is:
const { environment } = require('@rails/webpacker')
module.exports = environment
Any help on that would be greatly appreciated!
UPDATE
I should add that compiling my assets locally with
NODE_ENV=production ./bin/webpack
works perfectly fine.