2012-01-18 41 views
3

我有一個rails 3.1應用程序,我試圖推送到heroku。儘管推送起作用,但錯誤在於它試圖耙取資產。它得到一個錯誤運行`rake資產時出錯:預編譯`

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顯示,如果這會更有幫助。 我認爲這是一個常見的,簡單的修復錯誤,我只是不知道該怎麼做。

+0

向我們展示導致錯誤的application.js中的行可能會有所幫助。 – sosborn 2012-01-18 03:01:05

+0

這是奇怪的部分,app/assets/javascript/application.js只包含註釋。 – Vasseurth 2012-01-18 03:21:56

+0

你在那個目錄下還有什麼其他的javascript文件? – sosborn 2012-01-18 03:57:22

回答

5

看看這個網址這是幾乎相同的錯誤。 https://github.com/resolve/refinerycms/issues/1186

修復是在這裏: https://github.com/resolve/refinerycms/pull/1189

摘要:你失蹤「逗號」號或「分號」標誌的地方在你的application.js文件。 登錄完整跟蹤在這裏,同時通過下面的命令在本地運行:

bundle exec rake assets:precompile --trace 
+0

我沒有使用refinerycms – Vasseurth 2012-01-19 02:01:38

+0

誰說你正在使用refinerycms? 檢查錯誤和錯誤原因!您在應用程序中缺少逗號或分號。js文件或包含在application.js文件中的文件,就像你使用的是require樹(意味着每一個文件都將被包含在javascript文件夾中),我猜這些文件有些臃腫。 :( – 2012-01-19 06:09:16

+0

也粘貼這個命令的捆綁exec耙子資產的輸出:預編譯 - 跟蹤' – 2012-01-19 08:09:03

2

我的建議。刪除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幫助器庫,然後require_tree包含javascripts目錄中的每個其他文件。在您的本地機器上打開您的網站並查看源代碼。我敢打賭,你有一些額外的JavaScript文件,你沒有料到。

相關問題