Search code examples
rubyherokusinatrasequel

Error on heroku when starting an app `require': cannot load such file -- active_model (LoadError)


I'm new in the use of heroku AND ruby (which surely explain why I'm missing the point), here's my problem :

I have deployed previously a basic sinatra app on heroku without any issue, but I recently updated it with a database support with the Sequel ORM. While everything runs fine on my vagrant vhost, after deploying on heroku, the server crashed with a loaderror exception :

Jun 15 07:49:50 test-app heroku/web.1:  State changed from crashed to starting
Jun 15 07:50:01 test-app heroku/web.1:  Starting process with command `bundle exec thin start -p 23255`
Jun 15 07:50:09 test-app app/web.1:  /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require': cannot load such file -- activemodel            (LoadError)
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.5.2/lib/bundler.rb:131:in `require'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:7:in `block in <main>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:1:in `new'
Jun 15 07:50:09 test-app app/web.1:   from config.ru:1:in `<main>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `eval'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/rack/adapter/loader.rb:33:in `load'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:182:in `load_rackup_config'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:72:in `start'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:199:in `run_command'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/runner.rb:155:in `run!'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/bin/thin:6:in `<top (required)>'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/bin/thin:23:in `load'
Jun 15 07:50:09 test-app app/web.1:   from /app/vendor/bundle/ruby/1.9.1/bin/thin:23:in `<main>'
Jun 15 07:50:10 test-app heroku/web.1:  Process exited with status 1
Jun 15 07:50:10 test-app heroku/web.1:  State changed from starting to crashed

I'm pretty sure there's something related to the $LOAD_PATH specific in heroku environment but I can't find what's the problem since I can't reproduce it on my own environment (even in production mode, from a fresh installation, with the same command to start the server).

I tried several propositions for similar problems found here, like modifying Procfile or config.ru in different ways, or adding explicitely the activemodel Gem in the Gemfile, but nothing help me so far.

Any help will be much appreciated !

EDIT

Ok guys, following your advices, I add gem 'activerecord', not 'active_record' because Could not find gem 'active_record (>= 0) ruby' in the gems available on this machine. and no more complain from heroku, the app starts ...

But I need to understand :

  • Why requiring a gem I don't need nor require (I use sequel and as far as I know, it doesn't use active record at all)
  • Why I haven't any problem elsewhere than on heroku ?

Thanks


Solution

  • It turns out that heroku support was able to explain the problem to me:

    I'm loading all my models with a wildcard dir path

    Dir['./**/*_model.rb'].each { |m| require m }

    However, on heroku the gems are bundled within the path of the app, this means the following path matched my requirement:

    from /app/vendor/bundle/ruby/1.9.1/gems/sequel-4.11.0/lib/sequel/plugins/active_model.rb:1:in'`

    Including this file in my app includes the ActiveModel plugin for Sequel, which requires the active_model gem.

    Changing the require path of my models to include only the files from my app will do the trick and fix the dependencies issue.

    That's a very specific case related to a bad requirement design, where I can only blame myself, but in any case i'm posting the solution if someone hit the same problem one day.