运行`rake assets:precompile`时出错

时间:2012-01-18 02:57:39

标签: ruby-on-rails ruby-on-rails-3 heroku rake assets

我有一个rails 3.1应用程序,我试图推送到heroku。虽然推动工作,但错误在于它试图掠夺资产。它出错了

Unexpected token punc, expected punc (line: 11225, col: 7, pos: 321149)
undefined
(in /Users/Matt/Orchive/Orchive/app/assets/javascripts/application.js)

但是这个application.js文件只包含一些注释。这是:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree

我真的不了解资产,但我在推送之前尝试在终端中运行rake assets:precompile并获得了这个大错误

/Users/Matt/.rvm/rubies/ruby-1.9.2-p180/bin/ruby /Users/Matt/.rvm/gems/ruby-1.9.2-p180/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
Unexpected token punc, expected punc (line: 11225, col: 7, pos: 321149)

undefined
(in /Users/Matt/Orchive/Orchive/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile:primary
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/Matt/.rvm/rubies/ruby-1.9.2-p180/bi...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

我可以编辑此内容并将其更改为--trace显示的内容,如果这样会更有帮助的话。 我认为这是一个常见的,简单的修复错误,我只是不知道该怎么做。

2 个答案:

答案 0 :(得分:5)

看看这个网址这几乎是一样的错误。 https://github.com/resolve/refinerycms/issues/1186

修复在这里: https://github.com/resolve/refinerycms/pull/1189

摘要:您的application.js文件中某处缺少“逗号”标记或“分号”符号。 通过以下命令在本地运行时记录完整跟踪:

bundle exec rake assets:precompile --trace

答案 1 :(得分:3)

我的建议。删除require_tree行。这往往是矫枉过正,并造成更多问题。与在目录中添加所有内容相比,特别需要文件要好得多。

http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives

<强>解释即可。

您的逗号错位。或分号。它不太可能在jquery或jquery_ujs中,它可能在另一个文件中,但值得注意的是require_tree行:

//= require jquery
//= require jquery_ujs
//= require_tree

看看你的问题,你提到“但是这个application.js文件只包含一些注释。”那些不是评论!那些实际上需要这些文件并包含它们.Rails的神奇之处,在本例中是Sprockets,你可以编写一个javascript文件,并在顶部添加需要,其中包括顶部的所有文件。这样,您可以包含像jQuery这样的供应商库,但是您只需要使用一个javascript文件。

所以上面的那些注释包括jquery,rails jquery helper库,然后require_tree包含javascripts目录中的所有其他文件。在本地计算机上打开您的网站并查看源代码。我打赌你有一些你没想到的额外的javascript文件。