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

Most upvoted comments

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.

RAILS_ENV=production bundle exec rake assets:precompile
yarn install v1.3.2
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.74s.
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (>)
JS_Parse_Error.get ((execjs):3538:621)
(execjs):4060:48
(execjs):1:102
Object.<anonymous> ((execjs):1:120)
Module._compile (module.js:635:30)
Object.Module._extensions..js (module.js:646:10)
Module.load (module.js:554:32)
tryModuleLoad (module.js:497:12)
Function.Module._load (module.js:489:3)
Function.Module.runMain (module.js:676:10)
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
/Users/thomasthomas/.rvm/gems/ruby-2.4.2@rails_5_0/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in `call'
.....

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).