Search code examples
sinatrarackshotgun

Sinatra app - Shotgun don't work - "cannot load such file -- rack/commonlogger (LoadError)"


When I try to start my Sinatra-app with Shotgun I see LoadError:

E-MBP:test_app admin$ shotgun app.rb
/Users/admin/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require': cannot load such file -- rack/commonlogger (LoadError)
from /Users/admin/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
from /Users/admin/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
from /Users/admin/.rvm/gems/ruby-2.3.1/gems/shotgun-0.9.1/bin/shotgun:112:in `<top (required)>'
from /Users/admin/.rvm/gems/ruby-2.3.1/bin/shotgun:23:in `load'
from /Users/admin/.rvm/gems/ruby-2.3.1/bin/shotgun:23:in `<main>'
from /Users/admin/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/admin/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

There was no error before!

"ruby app.rb" still works and I see my main page in browser:

E-MBP:test_app admin$ ruby app.rb
== Sinatra (v1.4.7) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop

How can I fix that problem?


E-MBP:test_app admin$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
E-MBP:test_app admin$ rvm -v
rvm 1.27.0 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]

Sinatra folder contains only one file - test_app/app.rb:

require 'sinatra'

get '/' do
  "Hello!"
end

Gems rake/shotgun/sinatra are up to date:

E-MBP:test_app admin$ gem update rake
Updating installed gems
Nothing to update
E-MBP:test_app admin$ gem update shotgun
Updating installed gems
Nothing to update
E-MBP:test_app admin$ gem update sinatra
Updating installed gems
Nothing to update

Solution

  • I ran across the same error and found by adding gem 'shotgun' to my project's Gemfile and bundling I was able to get past that error.