Ruby-on-rails 尝试加载 gem 'uglifier' 时出错。(Bundler::GemRequireError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34420554/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:20:08  来源:igfitidea点击:

There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)

ruby-on-railsruby-on-rails-4server

提问by shibly

Why am i getting this error?

为什么我收到这个错误?

shibly@mybox:~/blog$ rails server
/home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /home/shibly/.gem/ruby/2.2.4/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /home/shibly/blog/config/application.rb:7:in `<top (required)>'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/shibly/.gem/ruby/2.2.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:9:in `require'
    from bin/rails:9:in `<main>

回答by Marcos Serpa

You should run following command to install NodeJS in Ubuntu

您应该运行以下命令在 Ubuntu 中安装 NodeJS

sudo apt-get install nodejs

or run this for OSX

或者为 OSX 运行这个

brew install nodejs

Uglifier is a JS wrapper and it needs a JS runtime running or JS interpreter. I would choose to install NodeJS.

Uglifier 是一个 JS 包装器,它需要一个 JS 运行时运行或 JS 解释器。我会选择安装 NodeJS。

回答by user3780968

In the default Rails Gemfile, the line for the gem 'therubyracer' is commented out. If you uncomment it, you'll get that gem and it should work.

在默认的 Rails Gemfile 中,gem 'therubyracer' 的行被注释掉了。如果你取消注释它,你会得到那个 gem,它应该可以工作。

From "Getting Started with Rails":

从“ Rails 入门”:

Compiling CoffeeScript and JavaScript asset compression requires you have a JavaScript runtime available on your system, in the absence of a runtime you will see an execjserror during asset compilation. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracergem to the generated Gemfilein a commented line for new apps and you can uncomment if you need it. therubyrhinois the recommended runtime for JRuby users and is added by default to the Gemfilein apps generated under JRuby. You can investigate all the supported runtimes at ExecJS.

编译 CoffeeScript 和 JavaScript 资产压缩要求您的系统上有可用的 JavaScript 运行时,如果没有运行时,您将execjs在资产编译期间看到错误。通常 Mac OS X 和 Windows 都安装了 JavaScript 运行时。Rails 将therubyracergem添加到Gemfile新应用程序的注释行中,如果需要,您可以取消注释。therubyrhino是 JRuby 用户推荐的运行时,默认情况下添加到Gemfile在 JRuby 下生成的应用程序中。您可以在ExecJS调查所有支持的运行时。

回答by gleb glazkov

There was an error with creating the db.

创建数据库时出错。

The problem is that the Node.js tried to install without sudoin the script:

问题是 Node.js 试图在没有sudo脚本的情况下安装:

sudo apt-get install nodejs