我正在尝试使用以下命令RAILS_ENV=production bundle exec rake assets:precompile
编译Rails 4.1.1应用程序的资产,但是当rails尝试编译资产时,它会给我一个错误。
错误如下所示,
$ RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
ExecJS::ProgramError: Unexpected character '#' (line: 13079, col: 0, pos: 361024)
Error
at new JS_Parse_Error (<eval>:2357:10623)
at js_error (<eval>:2357:10842)
at parse_error (<eval>:2357:12560)
at Object.next_token [as input] (<eval>:2357:17582)
at next (<eval>:2357:18881)
at semicolon (<eval>:2357:19726)
at simple_statement (<eval>:2357:22538)
at <eval>:2357:20689
at <eval>:2357:19938
at <eval>:2357:31926
at Object.parse (<eval>:2358:98)
(in /opt/rails/crj.com/app/assets/javascripts/application.js)/home/capin/.gem/ruby/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/home/capin/.gem/ruby/2.1.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:61:in `block (3 levels) in define'
/home/capin/.gem/ruby/2.1.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:60:in `block (2 levels) in define'
V8::Error: Unexpected character '#'
at js_error (<eval>:2357:10842)
at parse_error (<eval>:2357:12560)
at next_token (<eval>:2357:17582)
at next (<eval>:2357:18881)
at semicolon (<eval>:2357:19726)
at simple_statement (<eval>:2357:22538)
at <eval>:2357:20689
at <eval>:2357:19938
at <eval>:2357:31926
at parse (<eval>:2358:98)
at <eval>:19:24
at <eval>:53:3
/home/capin/.gem/ruby/2.1.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/home/capin/.gem/ruby/2.1.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:61:in `block (3 levels) in define'
/home/capin/.gem/ruby/2.1.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:60:in `block (2 levels) in define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
我尝试使用--trace
开关/选项运行上面提到的命令,但是对于导致此错误的原因我有点无能为力。可以在这里查看项目的完整性=&gt; https://github.com/ipatch/crj.com
答案 0 :(得分:14)
demo.js是一个JavaScript文件,但使用的是CoffeeScript注释(#
),而不是JavaScript注释(//
)。
答案 1 :(得分:5)
这很可能是因为rails会为您生成一个空的coffescript文件,作为您在项目中生成控制器的一部分。您也可能将coffescript重命名为.js
在空的js文件中,您将找到coffescript的自动生成的注释,该注释以#而不是//由javascript使用的#开头。只需删除所有评论,您就可以了。
由于出乎意料的&#39;#&#39;在您的示例的第13079行找到了字符,然后您就会在同一行找到您的评论。
答案 2 :(得分:0)
请删除任何.js文件中以“#”开头的注释行。