Chris Hunt
Chris Hunt

Reputation: 4030

'LoadError: cannot load such file' for local gem

I am using a local gem (herein, clearconnect) in a Rails application but receive the following error when trying to require it:

LoadError: cannot load such file -- clearconnect

This occurs regardless of where I attempt to require the gem. When the issue occurred initially the 'require' statement was in a lib file and I have since tried requiring it in 'config/application.rb' and also via the rails console but have not had success. Requiring other gems specified in the Gemfile of my application via the console were successful, if that is of any help.

Things I have tried/checked so far:

The .gem file corresponding to my gem has been placed in the vendor directory and the following line is in my Gemfile:

gem 'clearconnect', '0.0.1', :path => 'vendor'

Running bundle install after updating the Gemfile produced the following:

Using clearconnect (0.0.1) from source at vendor

'bundle exec gem list' lists my gem, as does running 'Gem.loaded_specs' from the Rails console.

I created a new Rails application and included my gem in the same way and received the same errors.

At this point I believe the problem to be either in the way I am specifying my gem in the Gemfile or an issue with the gem itself (though it has no issues locally). The gem can be found here: chrahunt/clearconnect.

Upvotes: 1

Views: 3589

Answers (2)

Chris Hunt
Chris Hunt

Reputation: 4030

The line

Using clearconnect (0.0.1) from source at vendor

does not confirm much besides the existence of the path specified in the Gemfile (confirmed by changing the path to point to another location and receiving no error). The other points being used to verify the gem was installed seem to operate in a similar fashion, leading to the real issue which was that Bundler does not support specifying a local .gem file in the Gemfile [github issue here]. The workaround mentioned in the issue:

Put the gem in vendor/cache and run (ironically) 'bundle install --no-cache'.

Worked just fine and I didn't have any further errors. I was also able to deploy the application to Heroku successfully without any additional configuration.

In summary:

Place the .gem file you would like to include in your application in the vendor/cache directory. Specify your gem in the Gemfile of your application like normal (no :path), making sure to state the version number explicitly. In my case this was:

gem 'clearconnect', '0.0.1'

Run bundle install --no-cache (reasoning here) and the issue should be resolved.

Upvotes: 1

Richard Jordan
Richard Jordan

Reputation: 8202

You need to put the full path to the gem, not just "vendor" but "vendor/gems/mygem-VERSION"

Upvotes: 1

Related Questions