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

前端 未结 6 514
刺人心
刺人心 2021-01-07 23:01

When trying to deploy a rails 5 app to heroku, I get the following error, when it reaches Running: rake assets:precompile:

remote:        ExecJS         


        
相关标签:
6条回答
  • 2021-01-07 23:35

    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)
    
    0 讨论(0)
  • 2021-01-07 23:44

    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

    0 讨论(0)
  • 2021-01-07 23:46

    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
    
    0 讨论(0)
  • 2021-01-07 23:52

    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"

    0 讨论(0)
  • 2021-01-07 23:54

    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

    0 讨论(0)
  • 2021-01-07 23:56

    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)
    
    0 讨论(0)
提交回复
热议问题