Saturday, October 30, 2010

Installing nokogiri for rails 3 app on Heroku

I wanted to install nokogiri gem defined in gemfile of my application on windows platform and i can see them installed when i do a git push heroku master.
But still i get an error saying no such file to load --nokogiri. My application on heroku gets crashed.

After many hours of research then i found these things below:

The problem was with Bundler gem and Bundler 1.0 Will Not Install Compiled Gems in UNIX When `bundle install` is Run in Windows.

When I run bundle install for my project under Windows, Bundler will generate a Gemfile.lock with the following for Nokogiri:

nokogiri (1.4.3.1-x86-mingw32)
nokogiri (1.4.3.1-x86-mswin32)

However, Gemfile.lock does not list the UNIX version nokogiri (1.4.3.1). I then checkin my Gemfile.lock into git and deploy a release to our Linux server. As part of our Cap script, the server runs bundle install --deployment. Upon doing so, there are four problems.

1. Bundler will not install the Nokogiri gem on the Linux server.
2. Bundler will list every other gem in its output, except for Nokogiri.
3. Bundler will say Your bundle is complete!, even though the Nokogiri gem was not installed.
4. Because Bundler does not exit with an error, Cap will deploy the app without Nokogiri being built, and the app errors out when a user tries a page that uses Nokogiri.

I believe this may also affect other compiled gems that have native mingw or mswin builds.

Solution: Remove your Gemfile.lock file and then do a repush.

2 comments:

  1. I tried what you told, but the heroku says that the gem file.lock is required when i repush after removed the gemfile.lock.
    what can i do?

    ReplyDelete
  2. Yes, Same here.
    Comment the solution if you found any.

    ReplyDelete