First attempt to run rails server and got “error while trying to load the gem ‘uglifier'”

By | 2nd January 2016

Background

  • OS: Debian 8
  • Ruby version: ruby 2.1.5p273 (2014-11-13) [i386-linux-gnu]
  • Rails version: Rails 4.2.5
  • Ruby and Rails are installed, created first hello world app, executed “bundle install”
  • Trying to run “rails server”
> rails server
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
/var/lib/gems/2.1.0/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 /var/lib/gems/2.1.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
        from /var/lib/gems/2.1.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'

Error occurs when loading gem uglifier.

Troubleshooting

Check Gemfile and found uglifier is not the first package installed and it is looking for any version after 1.3.0

> less Gemfile
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

Check /var/lib/gems/2.1.0/gems/ and version installed is 2.7.2

uglifier-2.7.2

Web search and found two references from stackoverflow.com to nodejs – “uglifier is a JS wrapper” and “therubyracer doesn’t install any JS runtime” hence it is necessary to install nodejs.

> sudo apt-get install nodejs

Run rails server again and it works!

> rails server
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
=> Booting WEBrick
=> Rails 4.2.5 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2016-01-02 11:06:38] INFO  WEBrick 1.3.1
[2016-01-02 11:06:38] INFO  ruby 2.1.5 (2014-11-13) [i386-linux-gnu]
[2016-01-02 11:06:38] INFO  WEBrick::HTTPServer#start: pid=18086 port=3000
^C[2016-01-02 11:06:42] INFO  going to shutdown ...
[2016-01-02 11:06:42] INFO  WEBrick::HTTPServer#start done.

Resources

  1. http://stackoverflow.com/questions/34420554/there-was-an-error-while-trying-to-load-the-gem-uglifier-bundlergemrequire
  2. http://stackoverflow.com/questions/34269101/rake-aborted-error-while-trying-to-load-the-gem-uglifier

One thought on “First attempt to run rails server and got “error while trying to load the gem ‘uglifier'”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.