简体   繁体   中英

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. If it matters, I've installed ruby in multi-user mode (rvm lives in /usr/local/rvm/bin/rvm).

I am setting up Capistrano to deploy my rails app. Everything works great except for when I include any CoffeeScript files. As part of the deploy process, Capistrano runs rake assets:precompile. This works just fine on my local environment (osx) but fails on my ubuntu. I've installed all the gems I think I need (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:

gem "therubyracer"

In my experience that JavaScript interpreter is required in Ubuntu different from OSX.

Hope this helps!

So after much digging I realized that this file had 0 length:

/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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