Ruby-on-rails Rake 中止,尝试加载 gem 'uglifier' 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34269101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rake aborted, Error while trying to load the gem 'uglifier'
提问by Sam Rodrigues
I'm following 'Getting Started with Ruby on Heroku', but when attempting to run the demo app locally with
我正在关注“Heroku 上的 Ruby 入门”,但是当尝试在本地运行演示应用程序时
$ bundle exec rake db:create db:migrate
I get
我得到
sam@samoliver:~/ruby-getting-started$ bundle exec rake db:create db:migrate --trace
rake aborted!
Bundler::GemRequireError: There was an error while trying to load the gem 'uglifier'.
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:72:in `each'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:72:in `block in require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:61:in `each'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:61:in `require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler.rb:99:in `require'
/home/sam/ruby-getting-started/config/application.rb:7:in `<top (required)>'
/home/sam/ruby-getting-started/Rakefile:4:in `require'
/home/sam/ruby-getting-started/Rakefile:4:in `<top (required)>'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/sam/.rvm/rubies/ruby-2.2.3/bin/rake:33:in `<main>'
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/sam/.rvm/gems/ruby-2.2.3/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in `autodetect'
/home/sam/.rvm/gems/ruby-2.2.3/gems/execjs-2.2.2/lib/execjs.rb:5:in `<module:ExecJS>'
/home/sam/.rvm/gems/ruby-2.2.3/gems/execjs-2.2.2/lib/execjs.rb:4:in `<top (required)>'
/home/sam/.rvm/gems/ruby-2.2.3/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `<top (required)>'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:77:in `require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:72:in `each'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:72:in `block in require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:61:in `each'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler/runtime.rb:61:in `require'
/home/sam/.rvm/gems/ruby-2.2.3/gems/bundler-1.11.0/lib/bundler.rb:99:in `require'
/home/sam/ruby-getting-started/config/application.rb:7:in `<top (required)>'
/home/sam/ruby-getting-started/Rakefile:4:in `require'
/home/sam/ruby-getting-started/Rakefile:4:in `<top (required)>'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/sam/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/sam/.rvm/rubies/ruby-2.2.3/bin/rake:33:in `<main>'
sam@samoliver:~/ruby-getting-started$
I tried removing and adding 'uglifier' (2.5.3) again to no effect and I do have 'therubyracer' installed, so I don't understand what is ExecJS complaining about.
我尝试再次删除并添加“uglifier”(2.5.3),但没有任何效果,而且我确实安装了“therubyracer”,所以我不明白 ExecJS 在抱怨什么。
Gemfile
文件
source 'https://rubygems.org'
ruby '2.2.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.3'
# Use postgresql as the database for Active Record
gem 'pg'
gem 'rails_12factor', group: :production
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
gem 'puma'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
回答by vipin
install nodejs
安装 nodejs
apt-get install nodejs
回答by Marcelo Alves Mesquita Junior
uncomment the line below in Gemfile
在 Gemfile 中取消注释下面的行
#gem 'therubyracer', platforms: :ruby
run in the terminal
在终端运行
bundle install
回答by Subhash Chandra
Uglifier is JavaScript compressor, so it need javascript runtime try installing nodejs
Uglifier 是 JavaScript 压缩器,所以它需要 javascript 运行时尝试安装 nodejs
Run this to install NodeJS in Ubuntu
运行此命令以在 Ubuntu 中安装 NodeJS
sudo apt-get install nodejs
or
或者
brew install nodejs
if you are on a OSX.
如果您使用的是 OSX。
回答by cinderpaina
I was having the same problem. I had to go into my root folder (on ubuntu use
我遇到了同样的问题。我必须进入我的根文件夹(在 ubuntu 上使用
sudo su)
From there use apt-get install nodejs, then exit the root and run bundle installthen you should be able to run rake db:migrate
从那里使用apt-get install nodejs,然后退出根目录并运行,bundle install然后您应该能够运行rake db:migrate
回答by algiztor
Try this:
尝试这个:
gem update --system 1.4.2

