Rake中止,尝试加载gem’uglifier’时出错
我正在关注“在Heroku上使用Ruby入门”,但在尝试在本地运行演示应用程序时
$ bundle exec rake db:create db:migrate
我明白了
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 `' /home/sam/ruby-getting-started/Rakefile:4:in `require' /home/sam/ruby-getting-started/Rakefile:4:in `' /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 `' 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 `' /home/sam/.rvm/gems/ruby-2.2.3/gems/execjs-2.2.2/lib/execjs.rb:4:in `' /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 `' /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 `' /home/sam/ruby-getting-started/Rakefile:4:in `require' /home/sam/ruby-getting-started/Rakefile:4:in `' /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 `' sam@samoliver:~/ruby-getting-started$
我尝试删除并添加’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]
安装nodejs
apt-get install nodejs
在Gemfile中取消注释下面的行
#gem 'therubyracer', platforms: :ruby
在终端跑
bundle install
Uglifier是JavaScript压缩器,所以需要javascript运行时尝试安装nodejs
运行此命令在Ubuntu中安装NodeJS
sudo apt-get install nodejs
要么
brew install nodejs
如果你在OSX上
我遇到了同样的问题。 我不得不进入我的根文件夹(在ubuntu上使用
sudo su)
从那里使用apt-get install nodejs
,然后退出root并运行bundle install
然后你应该能够运行rake db:migrate
试试这个:
gem update --system 1.4.2
- 使用Gemfile中的环境变量部署到Heroku
- 我无法将我的rails应用程序推送到Heroku /获取’pg’gem安装?
- 遵循Python / Flask Heroku教程时“foreman start”出错
- 多个heroku帐户无法正常工作
- 将暂存环境添加到工作流程
- 需要在Heroku上链接WP Blog和Rails App
- GroupingError:错误:列“”必须出现在GROUP BY子句中或用于聚合函数
- Sass :: SyntaxError:“position:”之后的CSS无效:期望的表达式(例如1px,粗体)
- Heroku + Rails错误ActiveRecord :: StatementInvalid