ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» when running rake assets:precompile on production

后端 未结 10 1353
小鲜肉
小鲜肉 2020-11-28 20:08

When deploying my Rails app I get the following error:

rake aborted!
   ExecJS::ProgramError: Unexpected token punc «(», expected punc «:» (line: 15, col: 14         


        
相关标签:
10条回答
  • 2020-11-28 20:53

    Here I found help for the same problem you had.

    Run rails console and:

    JS_PATH = "app/assets/javascripts/**/*.js"; 
    Dir[JS_PATH].each do |file_name|
      puts "\n#{file_name}"
      puts Uglifier.compile(File.read(file_name), harmony: true)
    end
    

    It will show you the file and the line where the Uglifier is making the problem.

    0 讨论(0)
  • 2020-11-28 20:53

    If Radovan's answer isn't working for you due to a problem in a library instead of your code, you can try upgrading Uglifier and enabling ES6 compilation.

    Gemfile.lock

    gem 'uglifier', '~> 4.1'
    

    config/environments/production.rb

    config.assets.js_compressor = Uglifier.new(harmony: true)
    
    0 讨论(0)
  • 2020-11-28 20:54

    I'm not sure of your build chain, but I got here by pasting the same error message into Google.

    That is called 'shorthand properties' in ES2015. I'm using Babel 6 with Gulp and needed to do an npm install babel-plugin-transform-es2015-shorthand-properties --save-dev and add that transform to my babel plugins.

    .pipe(babel({
        plugins: [
            'transform-es2015-shorthand-properties'
        ]
    }))
    

    https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-es2015-shorthand-properties

    0 讨论(0)
  • 2020-11-28 21:00

    December/2019 answer: starting on version 4.2.0 (released in Sept/2019), Uglifier now shows a beautiful (colored!) debug output showing you the offending line of code.

    I was having a Uglifier::Error: Unexpected character ''` error and I couldn't find it even following all the other solutions in this page.

    So go to your Gemfile, and set your Uglifier to be at least 4.2:

    # Use Uglifier as compressor for JavaScript assets
    gem 'uglifier', '>= 4.2'
    

    Run bundle update uglifier to update it.

    And then just look at the output, it will show you something like this:

    0 讨论(0)
提交回复
热议问题