Rails 5 Heroku deploy error: ExecJS::ProgramError: SyntaxError: Unexpected token: name (autoRegisterNamespace)

☆樱花仙子☆ 提交于 2019-12-01 02:32:52

It may have something to do with javascript/coffescript syntax. Check if you have let, it shout be replaced with var.

Edit - see @Guilherme Lages Santos's response. Uglifier added ES6 support since version 3.2.0 so you can just use it like this in your environment file

config.assets.js_compressor = Uglifier.new(harmony: true)

As the Uglifier official documentation says (https://github.com/lautis/uglifier):

"The experimental ES6 syntax support can be enabled by passing :harmony => true option to Uglifier."

Uglifier.compile(js, harmony: true)

So replace in config/environments/production.rb.

config.assets.js_compressor = :uglifier

with

config.assets.js_compressor = Uglifier.new(harmony: true)

I also had this issue.

It's important to remember that by default Heroku is precompiling in a production environment. When you run rake assets:precompile locally it's typically a development environment, which for me didn't exhibit the issue.

So in order to reproduce the issue locally, try

RAILS_ENV=production rake assets:precompile --trace

In my case I am using angularjs-rails gem and some how used es6 standard so solve it by commenting uglifier compressor in file config/environments/production.rb.

#config.assets.js_compressor = :uglifier

Seems to be some issues with newer ES syntax. Backtick's also won't pre-compile.

my example:

http://localhost:3000//${bike_file}.html

I changed to

"http://localhost:3000//" + bike_file + ".html"

I had this issue and it was throwing Uglifier::Error: Unexpected token: name (subscription)

It ended up being an actual syntax error.

I accidentally had left the words "cancel subscription" in one of my JS files and it was causing it to throw that error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!