NoMethodError:nil的未定义方法`spec':NilClass - active_utils,factory_girl和更多宝石失败

sho*_*rpt 6 rubygems ruby-on-rails

无处不在,并且没有改变任何东西,我开始得到这个错误(团队中的其他人也是如此).

这种情况发生在一些宝石(指定git分支的宝石)上,并且只在我们重新创建环境时(在vagrant中)才会发生.我们没有改变任何事情.

有任何想法吗?更多信息如下:

Using active_utils (2.0.0) from git://github.com/Shopify/active_utils.git (at v2.0.0)
NoMethodError: undefined method `spec' for nil:NilClass
An error occurred while installing active_utils (2.0.0), and Bundler cannot continue.
Make sure that `gem install active_utils -v '2.0.0'` succeeds before bundling.

Using factory_girl (2.6.5) from https://github.com/thoughtbot/factory_girl (at 2.6.x)
NoMethodError: undefined method `spec' for nil:NilClass
An error occurred while installing factory_girl (2.6.5), and Bundler cannot continue.
Make sure that `gem install factory_girl -v '2.6.5'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)
  • 运行"gem install active_utils -v'2.0.0'"有效但bundle总是失败.
  • 清除了宝石缓存,但没有帮助

好像它是Gemfile中的所有条目,指定一个开始失败的分支.

gem 'active_utils', :git => 'git://github.com/Shopify/active_utils.git', :branch => 'v2.0.0'
gem "will_paginate", :git => "git://github.com/mislav/will_paginate.git", :branch => "2-3-stable"
Run Code Online (Sandbox Code Playgroud)

sho*_*rpt 13

所以,事实证明这是由于最近升级到RubyGems引起的.强制使用以前的版本.

gem update --system 2.4.8
Run Code Online (Sandbox Code Playgroud)


Rys*_*aum 5

虽然已经有一个公认的答案,但我遇到了同样的问题。

最终,原因是我使用了过时的捆绑器版本,并更新至最新版本修复了该问题。有关该错误的更多信息,请参见此处:https : //github.com/bundler/bundler/issues/3560

该错误发生在捆绑程序版本1.9.3之前。

您可以通过运行gem install bundler 然后通过以下方法删除较旧的捆绑程序版本来更新捆绑程序:gem uninstall bundler -v old.bundler.version

如果您使用的是rvm,建议您rvm use @global在安装前通过运行将其安装在当前ruby版本的全局gemset上。