web-dev-qa-db-ja.com

Rakeは中止されました。gem 'uglifier'のロード中にエラーが発生しました

'Getting Started with Ruby on Heroku')に従っていますが、デモアプリをローカルで実行しようとすると

$ 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 `<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$ 

「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]
25
Sam Rodrigues

nodejsのインストール

apt-get install nodejs
46
vipin

gemfileで以下の行のコメントを解除します

#gem 'therubyracer', platforms: :Ruby

ターミナルで実行する

bundle install

UglifierはJavaScriptコンプレッサーなので、javascriptランタイムが必要ですnodejsをインストールしてみてください

これを実行してNodeJSをUbuntuにインストールします

Sudo apt-get install nodejs

または

brew install nodejs

oSXを使用している場合。

1
Subhash Chandra

これを試して:

gem update --system 1.4.2
0
algiztor

私は同じ問題を抱えていました。ルートフォルダーに移動する必要がありました(ubuntu使用時)

Sudo su)

そこからapt-get install nodejsを使用し、ルートを終了してbundle installを実行すると、rake db:migrateを実行できるはずです。

0
cinderpaina