繁体   English   中英

对用于Rails部署的Heroku ExecJS程序错误进行故障排除

[英]Troubleshooting Heroku ExecJS Program Error for Rails deployment

我正在尝试将新的Rails应用程序部署到heroku。 该应用程序在我的机器上运行良好,我可以将它从github拉到另一台机器上,并且在这里也运行良好。

但是,当尝试部署到heroku时,情况就不同了。 我一直在网上搜索与以下类似的错误:

ExecJS::ProgramError: Unexpected token name «of», expected punc «;» (line: 29885, col: 15, pos: 861062)

我在stackoverflow上看到的大多数问题在跟踪中都有错误提示。 但是我的踪迹并没有提供太多线索(行29885 ...?意外的标记“ of ... where ??”)。 我在这里有一个问题,我哪里概述了在js开发人员控制台中发现的内容,但这导致我走错了方向。

所有页面在本地都运行良好。

除了浏览器开发者控制台之外,还有什么方法可以解决此类错误?

$ RAILS_ENV=production bundle exec rake assets:precompile --trace
** 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::ProgramError: Unexpected token name «of», expected punc «;» (line: 29885, col: 15, pos: 861062)

Error
    at new JS_Parse_Error (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:10623)
    at js_error (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:10842)
    at croak (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:19086)
    at token_error (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:19223)
    at expect_token (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:19446)
    at expect (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:19584)
    at regular_for (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:23361)
    at for_ (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:23316)
    at /private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:21220
    at /private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:19957
    at block_ (/private/var/folders/7g/kc34ywms5j9bb5qgfcr0c7tw0000gn/T/execjs20150822-14064-japh2djs:2359:24599)new JS_Parse_Error ((execjs):2359:10623)
js_error ((execjs):2359:10842)
croak ((execjs):2359:19086)
token_error ((execjs):2359:19223)
expect_token ((execjs):2359:19446)
expect ((execjs):2359:19584)
regular_for ((execjs):2359:23361)
for_ ((execjs):2359:23316)
(execjs):2359:21220
(execjs):2359:19957
block_ ((execjs):2359:24599)
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:39:in `exec'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:21:in `eval'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:46:in `call'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/uglifier-2.7.1/lib/uglifier.rb:212:in `run_uglifyjs'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/uglifier-2.7.1/lib/uglifier.rb:179:in `compile'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/uglifier_compressor.rb:52:in `call'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/uglifier_compressor.rb:28:in `call'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/loader.rb:126:in `load_from_unloaded'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/loader.rb:60:in `block in load'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/loader.rb:286:in `fetch_asset_from_dependency_cache'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/loader.rb:44:in `load'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/cached_environment.rb:47:in `load'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/base.rb:66:in `find_asset'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/manifest.rb:138:in `block in find'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/path_utils.rb:223:in `block in stat_tree'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/path_utils.rb:204:in `each'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/path_utils.rb:204:in `stat_directory'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/path_utils.rb:222:in `stat_tree'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/legacy.rb:105:in `each'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/legacy.rb:104:in `each'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/manifest.rb:136:in `find'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/sprockets/manifest.rb:162:in `compile'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-3.3.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/Users/Travis/.rvm/gems/ruby-2.2.1/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/Users/Travis/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/Users/Travis/.rvm/gems/ruby-2.2.1/bin/rake:23:in `load'
/Users/Travis/.rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>'
/Users/Travis/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/Users/Travis/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile

Heroku日志向我显示了与上述相同的信息。

我的application.js文件:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require chartkick
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .



更新:

在删除了与js相关的文件并尝试一个一个地部署之后,结果是以下令人讨厌的代码(删除它使我可以毫无问题地部署到heroku。...很奇怪,在开发中使用此代码的任何页面都不会生成js浏览器开发者控制台中的错误,并且它们可以正常运行)

//assets/javascripts/accounts.js

$(document).on('page:change', function() {
  // var getFieldCount = function() {
  //   var accountType = $('#account_type').val();
  //   return $('.field.' + accountType).size();
  // };

  // Add classes to label each field under its account type for later easy grabbing in jQueries
  var accountFields = {}
  try {
    accountFields = JSON.parse($('#account_fields').val());
  } catch(jsonException) {
    //ignore errors without crashing
  }
  for (var accountType in accountFields) {
    var fields = accountFields[accountType];
    for (field of fields) {
      var field = $('#account_' + field).closest('.field');
      field.addClass(accountType);
    }
  }

  if ($('#edit_account').size() > 0) {
    var showCorrectFieldsPerAccountType = function() {
      $('.field').hide();
      var accountType = $('#account_type').val();
      var fields = accountFields[accountType];
      for (field of fields) {
        var field = $('#account_' + field).closest('.field');
        field.show();
      }
    };
    $('#account_type').change(showCorrectFieldsPerAccountType);
    showCorrectFieldsPerAccountType();
  }

  if ($('#new_account').size() > 0) {
    var showCorrectFieldsPerAccountType = function() {
      $('.field').hide();
      var accountType = $('#account_type').val();
      var fields = accountFields[accountType];
      for (field of fields) {
        var field = $('#account_' + field).closest('.field');
        field.show();
      }
    };
    $('#account_type').change(showCorrectFieldsPerAccountType);
    showCorrectFieldsPerAccountType();

    $("#account_type").prepend("<option value='' selected='selected'>Please Select</option>");
  }

});

如果您在JS lint工具(例如http://www.javascriptlint.com/online_lint.php )中加载了有问题的脚本(在您的Update中),则会看到以下错误:

for (field of fields) {

此行似乎是导致您原始错误的原因:

ExecJS::ProgramError: Unexpected token name «of», expected punc «;» (line: 29885, col: 15, pos: 861062)

您的Javascript似乎有一些问题,也可能来自您动态生成的Javascript文件。 尽管该应用程序在开发模式下运行,但是如果出现任何Javascript错误,则在部署时进行预编译时会抛出错误,因此您会遇到此错误。

解决此问题的一个好开始是在浏览器中查看您的Javascript console ,看看哪里有错误。 您的任何JS文件都可能出错,并且很可能在开发模式下的Javascript控制台中可见。

在Gemfile中添加gem therubyracer ,然后捆绑安装并推送更改,它将起作用

在Gemfile中

gem 'therubyracer' 

然后

app_root>$ bundle install

然后

app_root> $ bundle exec rake asset:precompile

然后将预编译的资产添加为git commit

然后

app_root>$ git push heroku master

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM