ExecJS :: RuntimeError:SyntaxError:意外的令牌运算符

时间:2016-11-24 06:21:58

标签: ruby-on-rails ruby-on-rails-4 asset-pipeline

RAILS_ENV=production rake assets:precompile --trace
Digest::Digest is deprecated; use Digest
Digest::Digest is deprecated; use Digest
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token operator «=», expected punc «,» (line: 159, col: 25, pos: 5132)

Error
    at new JS_Parse_Error (/tmp/execjs20161124-23752-1wuk17bjs:3623:11948)
    at js_error (/tmp/execjs20161124-23752-1wuk17bjs:3623:12167)
    at croak (/tmp/execjs20161124-23752-1wuk17bjs:3623:22038)
    at token_error (/tmp/execjs20161124-23752-1wuk17bjs:3623:22175)
    at expect_token (/tmp/execjs20161124-23752-1wuk17bjs:3623:22411)
    at expect (/tmp/execjs20161124-23752-1wuk17bjs:3623:22562)
    at ctor.argnames (/tmp/execjs20161124-23752-1wuk17bjs:3623:27486)
    at function_ (/tmp/execjs20161124-23752-1wuk17bjs:3623:27550)
    at /tmp/execjs20161124-23752-1wuk17bjs:3623:24469
    at /tmp/execjs20161124-23752-1wuk17bjs:3623:22954
new JS_Parse_Error ((execjs):3623:11948)
js_error ((execjs):3623:12167)
croak ((execjs):3623:22038)
token_error ((execjs):3623:22175)
expect_token ((execjs):3623:22411)
expect ((execjs):3623:22562)
ctor.argnames ((execjs):3623:27486)
function_ ((execjs):3623:27550)
(execjs):3623:24469
(execjs):3623:22954
/usr/local/rvm/gems/ruby-2.3.1/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
/usr/local/rvm/gems/ruby-2.3.1/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
/usr/local/rvm/gems/ruby-2.3.1/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
/usr/local/rvm/gems/ruby-2.3.1/gems/uglifier-3.0.3/lib/uglifier.rb:182:in `run_uglifyjs'
/usr/local/rvm/gems/ruby-2.3.1/gems/uglifier-3.0.3/lib/uglifier.rb:144:in `compile'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/uglifier_compressor.rb:52:in `call'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/uglifier_compressor.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:44:in `load'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:231:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:105:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:104:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:140:in `find'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:185:in `compile'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/rvm/gems/ruby-2.3.1/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:248:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:243:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:243:in `execute'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:180:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/task.rb:173:in `invoke'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:108:in `each'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:102:in `top_level'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:80:in `block in run'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
/usr/local/rvm/gems/ruby-2.3.1/gems/rake-11.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile

出现上述错误并中止资产创建。有关如何绕过它的任何帮助,因为生产中的Ajax文件不起作用。

1 个答案:

答案 0 :(得分:4)

我知道这已经过时了,但我也遇到了同样的错误,我来自Google,所以如果有人也这样做,这就是我的解决方案:

我在控制台中使用它来查找文件和错误行(从this answer获取):

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

我的错误是我使用的是新的ES6 javascript语法,与我的资产预编译不兼容。具体来说,在函数定义中定义默认参数,所以我从this answer

中获取了解决方案

而不是:

function foo(a, b = default_b) {
  ...
}

使用:

function foo(a, b) {
  b = typeof b !== 'undefined' ? b : 'default_b';
  ...
}