简体   繁体   English

ROR-耙式资产:预编译因“未定义CoffeeScript”而失败

[英]ROR - rake assets:precompile fails with 'CoffeeScript is not defined'

Hi I'm new to Rails and I've just recently setup a production environment on Ubuntu 12.04 with RVM. 嗨,我是Rails的新手,我最近才在具有RVM的Ubuntu 12.04上设置了生产环境。 If it matters, I've installed ruby in multi-user mode (rvm lives in /usr/local/rvm/bin/rvm). 如果重要的话,我已经在多用户模式下安装了ruby(rvm位于/ usr / local / rvm / bin / rvm中)。

I am setting up Capistrano to deploy my rails app. 我正在设置Capistrano来部署我的Rails应用程序。 Everything works great except for when I include any CoffeeScript files. 一切正常,除了我包含任何CoffeeScript文件时。 As part of the deploy process, Capistrano runs rake assets:precompile. 作为部署过程的一部分,Capistrano运行rake asset:precompile。 This works just fine on my local environment (osx) but fails on my ubuntu. 这在我的本地环境(osx)上工作正常,但在ubuntu上失败。 I've installed all the gems I think I need (coffee-script coffee-script-source). 我已经安装了我认为需要的所有宝石(coffee-script coffee-script-source)。 but it still doesn't work. 但它仍然不起作用。 Any pointers here? 这里有指针吗?

  * executing "cd -- /var/www/appname/releases/20130515220819 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
    servers: ["1.2.3.4"]
    [1.2.3.4] executing command
*** [err :: 1.2.3.4] rake aborted!
*** [err :: 1.2.3.4] ReferenceError: CoffeeScript is not defined
*** [err :: 1.2.3.4] (in /var/www/appname/releases/20130515220819/app/assets/javascripts/email_tests.js.coffee)
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:68:in `extract_result'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:19:in `eval'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:33:in `call'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/coffee-script-2.2.0/lib/coffee_script.rb:57:in `compile'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/tilt-1.3.7/lib/tilt/coffee.rb:46:in `evaluate'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/context.rb:193:in `block in evaluate'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `each'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/context.rb:190:in `evaluate'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/processed_asset.rb:12:in `initialize'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `new'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/base.rb:249:in `block in build_asset'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/base.rb:270:in `circular_call_protection'
*** [err :: 1.2.3.4] /usr/local/rvm/gems/ruby-1.9.3-p429/gems/sprockets-2.2.2/lib/sprockets/base.rb:248:in `build_asset'

Try adding this to your Gemfile: 尝试将其添加到您的Gemfile中:

gem "therubyracer"

In my experience that JavaScript interpreter is required in Ubuntu different from OSX. 以我的经验,与OSX不同,Ubuntu中需要JavaScript解释器。

Hope this helps! 希望这可以帮助!

So after much digging I realized that this file had 0 length: 因此,经过大量挖掘,我意识到该文件的长度为0:

/usr/local/rvm/gems/ruby-1.9.3-p429/gems/coffee-script-source-1.6.2/lib/coffee_script/coffee-script.js

This was simply fixed by running this from a normal user: 只需通过普通用户运行此命令即可解决:

rvmsudo gem pristine --all

I looked around on the internet and I'm the only person with this specific error. 我在互联网上四处张望,是唯一遇到此特定错误的人。 I have no idea how this file got truncated. 我不知道该文件如何被截断。 I hope this helps somebody else. 我希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM