本地 gem 的“LoadError:无法加载此类文件" [英] 'LoadError: cannot load such file' for local gem

查看:58
本文介绍了本地 gem 的“LoadError:无法加载此类文件"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 应用程序中使用本地 gem(此处为 clearconnect),但在尝试要求时收到以下错误:

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

无论我在哪里尝试需要 gem,都会发生这种情况.当问题最初发生时,'require' 语句位于 lib 文件中,此后我尝试在 'config/application.rb' 中以及通过 rails 控制台要求它,但没有成功.如果有帮助的话,通过控制台要求在我的应用程序的 Gemfile 中指定的其他 gem 是成功的.

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.

到目前为止我尝试/检查过的东西:

我的gem对应的.gem文件已经放到了vendor目录下,我的Gemfile中有如下一行:

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'

在更新 Gemfile 后运行 bundle install 产生以下结果:

Running bundle install after updating the Gemfile produced the following:

Using clearconnect (0.0.1) from source at vendor

'bundle exec gem list' 列出了我的 gem,就像从 Rails 控制台运行 'Gem.loaded_specs' 一样.

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

我创建了一个新的 Rails 应用程序并以相同的方式包含我的 gem 并收到相同的错误.

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

在这一点上,我认为问题要么是我在 Gemfile 中指定我的 gem 的方式,要么是 gem 本身的问题(尽管它在本地没有问题).可以在此处找到 gem:chrahunt/clearconnect.

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.

推荐答案

使用来自供应商源代码的 clearconnect (0.0.1)

除了 Gemfile 中指定的路径的存在之外,没有太多确认(通过将路径更改为指向另一个位置并且没有收到错误来确认).用于验证 gem 安装的其他点似乎以类似的方式运行,导致真正的问题是 Bundler 不支持在 Gemfile 中指定本地 .gem 文件 [github issue 这里].问题中提到的解决方法:

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:

将 gem 放入 vendor/cache 并运行(讽刺的是)'bundle install --no-cache'.

工作得很好,我没有任何进一步的错误.我还能够在没有任何额外配置的情况下成功地将应用程序部署到 Heroku.

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.

总结:

将要包含在应用程序中的 .gem 文件放在 vendor/cache 目录中.像平常一样在应用程序的 Gemfile 中指定您的 gem(没有 :path),确保明确说明版本号.就我而言,这是:

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'

运行 bundle install --no-cache(推理 此处),问题应该得到解决.

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

这篇关于本地 gem 的“LoadError:无法加载此类文件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆