webpacker: rake assets:precompile fails
Everything seems to be working fine in development, however when trying to deploy I’m getting an error.
Output of running command is as follows:
rake assets:precompile RAILS_ENV=production
yarn install v0.27.5
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.93s.
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: name (key)
JS_Parse_Error.get ((execjs):3538:621)
(execjs):4060:47
(execjs):1:102
Object.<anonymous> ((execjs):1:120)
Module._compile (module.js:570:32)
Object.Module._extensions..js (module.js:579:10)
Module.load (module.js:487:32)
tryModuleLoad (module.js:446:12)
Function.Module._load (module.js:438:3)
Module.runMain (module.js:604:10)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 19 (8 by maintainers)
Commits related to this issue
- [fix]production build failure LoadError: cannot load such file -- uglifier https://github.com/rails/webpacker/issues/602 — committed to mikutas/last-time-webapp by mikutas 4 years ago
- [fix]production build failure LoadError: cannot load such file -- uglifier https://github.com/rails/webpacker/issues/602 — committed to mikutas/last-time-webapp by mikutas 4 years ago
@iamraffe @tthomas7
https://github.com/lautis/uglifier/issues/116#issuecomment-347386669
Same exact issue, this fixed it for me
Sorry, I probably should have mentioned @iamraffe to see if he had a solution as our issues are very similar. I’m in the process of moving my javascript code away from the rails asset pipeline into webpacker but I haven’t migrated all of it yet. And the problem seems to be with the rails uglifier and the webpack generated code.
If I remove this line from production.rb, the problem goes away.
config.assets.js_compressor = :uglifier
With that line in place though I can’t deploy to Heroku because compiling the assets fails. And without that line all the code I have yet to migrate to webpack doesn’t get minified.
I know that once I’ve migrated all the code to webpacker I won’t need the rails uglifier and fortunately I have a relatively small code base so I’m working on that. But I suspect others will struggle here more than I have.
@iamraffe You don’t need uglifier with Webpack. The Webpacker already does this if you run
webpacker:compile
- https://github.com/rails/webpacker/blob/master/lib/install/config/webpack/production.js#L16. The error you are getting is related to JS syntax that ruby uglifier can’t recognise (running same thing twice).