There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Solution 1
You should run following command to install NodeJS in Ubuntu
sudo apt-get install nodejs
or run this for 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.
Solution 2
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.
From "Getting Started with 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
execjs
error during asset compilation. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds thetherubyracer
gem to the generatedGemfile
in a commented line for new apps and you can uncomment if you need it.therubyrhino
is the recommended runtime for JRuby users and is added by default to theGemfile
in apps generated under JRuby. You can investigate all the supported runtimes at ExecJS.
shibly
Updated on March 29, 2020Comments
-
shibly about 4 years
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>
-
DragonKnight over 8 yearswhy it needs js env?
-
Alankar More about 8 yearsIt works :) Thanks, But why we need this nodejs to be installed ?
-
Marcos Serpa about 8 yearsWe need a JS Runtime, @AlankarMore ;). So, NodeJS this is usually my choice, mainly because it's built on Chrome's V8 engine (developers.google.com/v8). We have a lot of JS today at Rails. And we need an environment set to run all that stuff. That includes wrappers, runtimes/interpreters...
-
Rok Strniša about 8 yearsIf installing nodejs from source, make sure the binary is installed to
/usr/bin/nodejs
where execjs expects to find it. -
ConnorWGarvey over 7 yearsThanks! This was easier and seems cleaner than relying on NodeJS.
-
Aboozar Rajabi about 7 years@MarcosSerpa Thanks! It works for me, too. And I have a question. Is the Nodejs an essential requirement for installing and using Ruby on Rails even when you're not using it directly?
-
Marcos Serpa about 7 years@AboozarRajabi Nodejs is not an essential, but a JS runtime or interpreter is. And this is the role of NodeJS here, to our case. If not NodeJS, you'll need another JS runtime/interpreter.
-
Cyril Duchon-Doris about 7 yearsWhile this answer works it eludes that you should rather have (for production) a proper execjs runtime like node.js
-
Kasperi almost 7 yearsFor people struggling with this on Rails 2.4 (where nodejs doesn't solve the problem): stackoverflow.com/questions/41461977/…
-
Chloe over 6 yearsWhy isn't there a native Ruby JavaScript interpreter? There's one for Java. Then
uglifier
can just depend on that gem, andbundler
will install everything correctly the first time.