预编译资产失败ExecJS :: ProgramError:意外的令牌:operator(=)(行:10770,col:0,pos:300859)

时间:2015-05-23 21:59:14

标签: ruby-on-rails ruby git heroku

我在将rails项目推送到heroku时遇到问题。我收到“预编译资产失败”消息。我是编程新手,也是ruby on rails的新手。我真的需要一些帮助。这是我命令行中的文本。

 $ git push heroku master
Counting objects: 76, done.
Compressing objects: 100% (63/63), done.
Writing objects: 100% (76/76), 27.38 KiB | 11.00 KiB/s, done.
Total 76 (delta 4), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.0.0
remote: ###### WARNING:
remote:        Removing `Gemfile.lock` because it was generated on Windows.
remote:        Bundler will do a full resolve so native gems are handled properl
y.
remote:        This may result in unexpected gem versions being used in your app
.
remote:        In rare occasions Bundler may not be able to resolve your depende
ncies at all.
remote:        https://devcenter.heroku.com/articles/bundler-windows-gemfile
remote:
remote: -----> Installing dependencies using 1.9.7
remote:        Running: bundle install --without development:test --path vendor/
bundle --binstubs vendor/bundle/bin -j4
remote:        Fetching gem metadata from https://rubygems.org/............
remote:        Fetching version metadata from https://rubygems.org/...
remote:        Fetching dependency metadata from https://rubygems.org/..
remote:        Resolving dependencies....
remote:        Rubygems 2.0.14 is not threadsafe, so your gems must be installed
 one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem insta
llation.
remote:        Installing rake 10.4.2
remote:        Installing i18n 0.7.0
remote:        Installing multi_json 1.11.0
remote:        Installing activesupport 3.2.21
remote:        Installing builder 3.0.4
remote:        Installing activemodel 3.2.21
remote:        Installing erubis 2.7.0
remote:        Installing journey 1.0.4
remote:        Installing rack 1.4.5
remote:        Installing rack-cache 1.2
remote:        Installing rack-test 0.6.3
remote:        Installing hike 1.2.3
remote:        Installing tilt 1.4.1
remote:        Installing sprockets 2.2.3
remote:        Installing actionpack 3.2.21
remote:        Installing mime-types 1.25.1
remote:        Installing polyglot 0.3.5
remote:        Installing treetop 1.4.15
remote:        Installing mail 2.5.4
remote:        Installing actionmailer 3.2.21
remote:        Installing arel 3.0.3
remote:        Installing tzinfo 0.3.44
remote:        Installing activerecord 3.2.21
remote:        Installing activeresource 3.2.21
remote:        Using bundler 1.9.7
remote:        Installing coffee-script-source 1.9.1.1
remote:        Installing execjs 2.5.2
remote:        Installing coffee-script 2.4.1
remote:        Installing rack-ssl 1.3.4
remote:        Installing json 1.8.2
remote:        Installing rdoc 3.12.2
remote:        Installing thor 0.19.1
remote:        Installing railties 3.2.21
remote:        Installing coffee-rails 3.2.2
remote:        Installing jquery-rails 3.1.2
remote:        Installing pg 0.18.2
remote:        Installing rails 3.2.21
remote:        Installing sass 3.4.14
remote:        Installing sass-rails 3.2.6
remote:        Installing uglifier 2.7.1
remote:        Bundle complete! 6 Gemfile dependencies, 40 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Post-install message from rdoc:
remote:        Depending on your version of ruby, you may need to install ruby r
doc/ri data:
remote:        <= 1.8.6 : unsupported
remote:        = 1.8.7 : gem install rdoc-data; rdoc-data --install
remote:        = 1.9.1 : gem install rdoc-data; rdoc-data --install
remote:        >= 1.9.2 : nothing to do! Yay!
remote:        Bundle completed (54.39s)
remote:        Cleaning up the bundler cache.
remote: -----> Writing config/database.yml to read from DATABASE_URL
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/p
lugins! Support for these plugins will be removed in Rails 4.0. Move them out an
d bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and
 config/initializers/myplugin.rb. See the release notes for more on this: http:/
/weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from
 <top (required)> at /tmp/build_7f6590528210ec3b45a43e69c0119446/Rakefile:7)
remote:        DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/p
lugins! Support for these plugins will be removed in Rails 4.0. Move them out an
d bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and
 config/initializers/myplugin.rb. See the release notes for more on this: http:/
/weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from
 <top (required)> at /tmp/build_7f6590528210ec3b45a43e69c0119446/Rakefile:7)
remote:        rake aborted!
remote:        ExecJS::ProgramError: Unexpected token: operator (=) (line: 10770
, col: 0, pos: 300859)
remote:        Error
remote:        at new JS_Parse_Error (/tmp/execjs20150523-743-1p3uckwjs:2359:106
23)
remote:        at js_error (/tmp/execjs20150523-743-1p3uckwjs:2359:10842)
remote:        at croak (/tmp/execjs20150523-743-1p3uckwjs:2359:19086)
remote:        at token_error (/tmp/execjs20150523-743-1p3uckwjs:2359:19223)
remote:        at unexpected (/tmp/execjs20150523-743-1p3uckwjs:2359:19311)
remote:        at expr_atom (/tmp/execjs20150523-743-1p3uckwjs:2359:27526)
remote:        at maybe_unary (/tmp/execjs20150523-743-1p3uckwjs:2359:30019)
remote:        at expr_ops (/tmp/execjs20150523-743-1p3uckwjs:2359:30777)
remote:        at maybe_conditional (/tmp/execjs20150523-743-1p3uckwjs:2359:3086
9)
remote:        at maybe_assign (/tmp/execjs20150523-743-1p3uckwjs:2359:31312)
remote:        at expression (/tmp/execjs20150523-743-1p3uckwjs:2359:31625)
remote:        at simple_statement (/tmp/execjs20150523-743-1p3uckwjs:2359:22563
)
remote:        at /tmp/execjs20150523-743-1p3uckwjs:2359:20468
remote:        (in /tmp/build_7f6590528210ec3b45a43e69c0119446/app/assets/javasc
ripts/application.js)new JS_Parse_Error ((execjs):2359:10623)
remote:        js_error ((execjs):2359:10842)
remote:        croak ((execjs):2359:19086)
remote:        token_error ((execjs):2359:19223)
remote:        unexpected ((execjs):2359:19311)
remote:        expr_atom ((execjs):2359:27526)
remote:        maybe_unary ((execjs):2359:30019)
remote:        expr_ops ((execjs):2359:30777)
remote:        maybe_conditional ((execjs):2359:30869)
remote:        maybe_assign ((execjs):2359:31312)
remote:        expression ((execjs):2359:31625)
remote:        simple_statement ((execjs):2359:22563)
remote:        (execjs):2359:20468
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/execjs-2.5.2/lib/execjs/external_runtime.rb:39:in `exec'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/execjs-2.5.2/lib/execjs/external_runtime.rb:21:in `eval'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/execjs-2.5.2/lib/execjs/external_runtime.rb:46:in `call'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/uglifier-2.7.1/lib/uglifier.rb:212:in `run_uglifyjs'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/uglifier-2.7.1/lib/uglifier.rb:179:in `compile'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/compressors.rb:74:in `compress'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/processing.rb:265:in `block in js_compres
sor='
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `call'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `evaluate'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/context.rb:193:in `block in evaluate'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `each'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `evaluate'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/bundled_asset.rb:26:in `initialize'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:252:in `new'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:252:in `build_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/index.rb:60:in `find_asset'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/static_compiler.rb:19:in `block in comp
ile'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:219:in `block in each_logical_pat
h'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:206:in `block (2 levels) in each_
file'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each_entry'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:204:in `block in each_file'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each_file'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/sprockets-2.2.3/lib/sprockets/base.rb:217:in `each_logical_path'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/static_compiler.rb:18:in `compile'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/assets.rake:56:in `internal_precompile'

remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/assets.rake:70:in `block (3 levels) in
<top (required)>'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/assets.rake:60:in `block (3 levels) in
<top (required)>'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/assets.rake:23:in `invoke_or_reboot_rak
e_task'
remote:        /tmp/build_7f6590528210ec3b45a43e69c0119446/vendor/bundle/ruby/2.
0.0/gems/actionpack-3.2.21/lib/sprockets/assets.rake:29:in `block (2 levels) in
<top (required)>'
remote:        Tasks: TOP => assets:precompile:primary
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:
remote:  !     Push rejected, failed to compile Ruby app
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to whispering-chamber-4883.
remote:
To https://git.heroku.com/whispering-chamber-4883.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/whispering-chamber-48
83.git'

感谢。

5 个答案:

答案 0 :(得分:16)

你现在可能已经解决了这个问题,但我偶然发现了这个问题并希望分享我的解决方案。

如上面的答案所示,跟踪错误到问题文件的最佳方法是运行

rake assets:precompile RAILS_ENV=production

在本地

,排除您认为包含问题的文件或目录。我逐个删除了目录(之后我可以从我的仓库再次检出),直到我开始预编译。然后我深入到最后删除的目录,并将其追溯到某个文件和表单

的函数
array.find(name => name.id === user_id);

我的研究表明,最大的Javascript更新(ES5)于2009年发布,从那时起,2015年6月只有unitl发布了ECMAScript 6(ES6)最终规范。 ES6支持此函数中使用的语法,但Rails上不支持ES5和ES6(我运行的是RoR 5.0.0.1),至少不支持资产管道上的ExecJS。

您可以做的是将您的功能更改为替代语法,即

array.find(function(name){return name.id === user_id});

它应该等效地工作。

  • 有关find函数here
  • 的更多信息
  • 要让ES6使用RoR,您可能需要查看Babel,如上所述here

答案 1 :(得分:1)

我有一个非常类似的问题,它不会让我因为(&gt;)而进行预编译。我几乎通过删除不同的文件并查看预编译是否有效来跟踪攻击文件。我甚至将其追溯到这种方法:

tagIsUnique: function(){ return this.tags.findIndex( item => this.tag.toLowerCase() === item.toLowerCase() ) < 0; }

然后我改变它,以便它不再有令人讨厌的箭头。

答案 2 :(得分:0)

错误消息表明您的一个JavaScript(或Cof​​feeScript)文件存在语法错误。遗憾的是,该消息并未提供足够的信息来查找正确的资产和行号。但是,您可以通过

在本地预编译来缩小搜索范围

rake assets:precompile

哪个应输出与

类似的内容
ExecJS::RuntimeError: Unexpected token: operator (=)
  (in /path/to/railsapp/app/assets/javascripts/path/to/asset.js)
...

这表示错误位于文件path/to/asset.js中。在不知道这个文件的内容的情况下,我只能猜测你在那里的某个地方放错了=。仔细查看该文件,看看是否有任何不合适的地方。

请注意,在本地运行rake assets:precompile会在public/assets/中生成资源。您想要将它们检查到您的git存储库中,请确保在将修复程序提交到损坏的资产文件之前删除它们。

答案 3 :(得分:0)

在JavaScript中搜索operator =。你会证明你输了= =。

遥控器:耙子中止了! remote:ExecJS :: ProgramError:意外的标记:operator(=)(行:10770 ,col:0,pos:300859)

答案 4 :(得分:0)

我有一个非常类似的问题,并且正如我提到的那样,因为我的Rails版本不支持ES6。升级链轮虽然对我有用。我最终要做的是升级uglifier,然后在我的production.rb中进行更改,

config.assets.js_compressor = :uglifier

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

然后我的预编译就像一个咒语。

我认为这是同样的问题:ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (>) (line: 22342, col: 24, pos: 826182)