hleinone
hleinone

Reputation: 4480

Heroku app fails to start - `require': no such file to load -- sinatratestapp (LoadError)

I'm trying to get my Heroku app to run using the bamboo-mri-1.9.2 stack. Of course it's running fine locally on Ruby 1.9.2. But when on production it crashes during the startup on executing config.ru which looks like this:

require 'sinatratestapp'
run Sinatra::Application

My .gems file:

sinatra --version '>= 1.0'

And the application itself as sinatratestapp.rb:

require 'rubygems'
require 'sinatra'

get '/' do
  "Hello from Sinatra on Heroku!"
end

That's all I've got in the project and trying to run that on Heroku results:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- sinatratestapp (LoadError)
        from <internal:lib/rubygems/custom_require>:29:in `require'
        from config.ru:1:in `block (3 levels) in <main>'
        ...
-----> Your application is requiring a file that it can't find.

       Most often this is due to missing gems, or it could be that you failed
       to commit the file to your repo.  See http://docs.heroku.com/gems for
       more information on managing gems.

       Examine the backtrace above this message to debug.

I've tried to do as it guides but as a Ruby noob my examinations have resulted nothing.

Upvotes: 12

Views: 9500

Answers (5)

cramhead
cramhead

Reputation: 1067

Thanks for the tip. There was no mention of the .gems file in the Heroku post http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/

Upvotes: 0

recursive
recursive

Reputation: 494

You can put the following line in your config.ru file and it will fix the issue as well. This is also going to carry application wide, so it will bring back the feeling of pre-1.9.2 behavior:

$LOAD_PATH.unshift(Dir.getwd)

NOTE: I was unable to test on Heroku

MY PROBLEM: Getting unicorn to behave properly with a (ruby < 1.9.2) sinatra application without a Gemfile, config.ru, or config/unicorn.rb.

Upvotes: 3

hleinone
hleinone

Reputation: 4480

By the help of Heroku support request and this question I found out the solution.

Ruby 1.9.2 doesn't automatically include "." in the $LOAD_PATH. To workaround this, modify config.ru by stating require './sinatratestapp' instead of require 'sinatratestapp'.

Upvotes: 38

Joost Schuur
Joost Schuur

Reputation: 4482

I believe I ran into this problem when experimenting with Sinatra. Ruby 1.9 doesn't include the current directory in the path by default, so you have to implicitly state require 'sinatratestapp' in our config.ru file.

Upvotes: 1

agentargo
agentargo

Reputation: 401

My Sinatra projects have the same layout and look about the same, the only difference is that in my .gems file I do not specify a version.

my .gems looks like this:

sinatra
hpricot

Upvotes: -1

Related Questions