Rails 资产预编译神秘错误
我在资产预编译中遇到了一个非常令人讨厌且持续存在的问题,我似乎无法自己解决。在某些没有错误的文件中编译总是失败。例如,以下错误位于仅包含注释的文件 copies.js.coffee
中。如果我删除该文件,另一个文件将会出现错误。我所有资源文件的类型都是 us-ascii
- 任何文件中都没有奇怪的字符。我正在使用 Rails 3.1.3。我已经尝试过 Ruby 1.9.2 和 1.9.3 - 没有区别。
$ rake assets:precompile --trace
(in /cygdrive/c/Development/artwork2)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/kari/.rvm/rubies/ruby-1.9.3-p0/bin/ruby.exe /home/kari/.rvm/gems/ruby-1.9.3-p0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
湉異⁴牅潲㩲唠歮潮湷漠瑰潩⼢祣摧楲敶振唯敳獲欯牡⽩灁䑰瑡⽡潌慣⽬敔灭支數橣㉳〲ㄱⴲ㔵〲㐭瀶湸⸱獪•灳捥晩敩
(in /cygdrive/c/Development/artwork2/app/assets/javascripts/copies.js.coffee)
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:150:in `exec_runtime'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:27:in `block in exec'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:40:in `compile_to_tempfile'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:26:in `exec'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:18:in `eval'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:32:in `call'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:57:in `compile'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/coffee.rb:46:in `evaluate'
这真的很烦人,我无法前进。我几乎尝试了从这里和其他地方找到的所有东西。
补充:我在 cygwin 和 Ubuntu 下的 rvm 中都尝试过这个。
I have a really nasty and persistent problem in assets precompile which I seem not to be able to solve by myself. The compilation always fails in some file that does not have an error. For example the error below is in the file copies.js.coffee
that has only a comment. If I delete that file, another file will have the error. The type of all my asset files is us-ascii
- no strange characters in any file. I am using Rails 3.1.3. I have tried both with Ruby 1.9.2 and 1.9.3 - no difference.
$ rake assets:precompile --trace
(in /cygdrive/c/Development/artwork2)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/home/kari/.rvm/rubies/ruby-1.9.3-p0/bin/ruby.exe /home/kari/.rvm/gems/ruby-1.9.3-p0/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
湉異⁴牅潲㩲唠歮潮湷漠瑰潩⼢祣摧楲敶振唯敳獲欯牡⽩灁䑰瑡⽡潌慣⽬敔灭支數橣㉳〲ㄱⴲ㔵〲㐭瀶湸⸱獪•灳捥晩敩
(in /cygdrive/c/Development/artwork2/app/assets/javascripts/copies.js.coffee)
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:150:in `exec_runtime'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:27:in `block in exec'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:40:in `compile_to_tempfile'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:26:in `exec'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:18:in `eval'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/execjs-1.2.13/lib/execjs/external_runtime.rb:32:in `call'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/coffee-script-2.2.0/lib/coffee_script.rb:57:in `compile'
/home/kari/.rvm/gems/ruby-1.9.3-p0/gems/tilt-1.3.3/lib/tilt/coffee.rb:46:in `evaluate'
This is really annoying and I am not able to get forward. I have tried almost everything I have found from here and from elsewhere.
An addition: I have tried this both in cygwin and in Ubuntu under rvm in both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从外观上看,其中一个 JavaScript 文件在某种程度上是无效的。
我假设一切都在开发模式下正确运行,也就是说一切都在浏览器中正常运行?
如果是这样,则代码在开发中可以正确运行,因为所有文件都以调试模式提供 - 它们不会被连接或压缩。编译时,它们首先被连接,然后被压缩。
该问题可能是所包含文件之一中存在缺少分号形式的语法错误。 Javascript 压缩器需要这些来确定一个代码块的结束位置和另一个代码块的开始位置。第一个要检查的地方是插件定义的末尾。假设问题仅出现在一个文件中,您可以一次只删除一个文件,编译它直到它运行,然后您就找到了罪魁祸首。
By the looks of it one of the javascript files is not valid in some way.
I am presuming that everything runs correctly in development mode, that is everything functions correctly in the browser?
If this is so, the code runs correctly in development because all the files are served in debug mode - they are not concatenated or compressed. When compiled they are first concatenated and then compressed.
The problem will likely be a syntax error in one of the included files in the form of a missing semicolon. Javascript compressors need these to determine where one block of code ends and another begins. The first place to check is the end of plugin definitions. Assuming the problem is in one file only you could remove just one file at time, compile it until it runs, and you have your culprit.
问题出在咖啡轨上。我从资产中删除了所有生成的咖啡文件。它们只包含生成的评论,没有其他内容。之后,资产按其应有的方式编译。某处一定有严重的错误。花了几个小时。感谢理查德提出的方法。
The problem was in coffee-rails. I removed all generated coffee files from assets. They contained only generated comments, nothing else. After that the assets compiled as they should have been. There must be a bad bug somewhere. It took couple of hours. Thank you Richard for suggesting the method.