簡體   English   中英

運行`rake assets:precompile`時出錯

[英]Error when running `rake assets:precompile`

我有一個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在推送之前在終端中進行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如果這會更有幫助。 我認為這是一個常見的,簡單的修復錯誤,我只是不知道該怎么做。

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

修復程序在這里: https//github.com/resolve/refinerycms/pull/1189

簡介:您的application.js文件中某處缺少“逗號”符號或“分號”符號。 通過以下命令在本地運行時記錄完整跟蹤:

bundle exec rake assets:precompile --trace

我的建議。 刪除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文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM