Rails 加载错误 - bcrypt 的库版本不兼容

Rails Load Error - incompatible library version for bcrypt

我的 rails srails c 突然开始拒绝启动并出现以下错误。我不记得有更新或删除任何 gem。非常感谢任何解决问题的帮助。

incompatible library version - /Users/[me]/projects/[app]/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.12/lib/bcrypt_ext.bundle (LoadError)

bcrypt 在我们的项目中不是明确要求的 gem,但它包含在 Gemfile.lock 中,因为它是一个依赖项:bcrypt (3.1.12)

到目前为止我已经尝试了这些,但我得到了同样的错误:

  1. 正在我的系统中卸载和安装 bcrypt(根据此
gem uninstall bcrypt -v 3.1.12

You have requested to uninstall the gem:
        bcrypt-3.1.12

sorcery-0.14.0 depends on bcrypt (~> 3.1)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled bcrypt-3.1.12
gem install bcrypt -v 3.1.12
Successfully installed bcrypt-3.1.12
  1. gem pristine --all

以下是我检查 gem 版本时得到的结果:

  1. gem info bcrypt
*** LOCAL GEMS ***
bcrypt (3.1.12)
    Author: Coda Hale
    Homepage: https://github.com/codahale/bcrypt-ruby
    License: MIT
    Installed at: /Users/[me]/.rvm/gems/ruby-2.6.2

    OpenBSD's bcrypt() password hashing algorithm.
  1. bundle info bcrypt
* bcrypt (3.1.12)
        Summary: OpenBSD's bcrypt() password hashing algorithm.
        Homepage: https://github.com/codahale/bcrypt-ruby
        Path: /Users/[me]/projects/[app]/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.12

[已解决]

[解决方案 1] 我需要 uninstall/reinstall vendor/bundle 文件夹中的 gem,而不是 gem uninstallgem install.

以下是涉及的步骤:

  1. 使用 otool -L 检查您的 gem 的保存位置(我的保存在此处:[project root]/vendor/bundle/ruby/2.6.0/gems/bcrypt-3.1.12/lib/bcrypt_ext.bundle

  2. 删除 bcrypt-3.1.12 文件夹中包含 rm -rf 的所有内容。

  3. bundle install --force --path vendor/bundle 重新安装 bcrypt-3.1.12 gem.

[解决方案 2] 我最终做的是用 bundle update bcrypt 更新 bcrypt 的版本。猜测此更新在 vendor/bundle 中干净地安装了 gem,因为我所有的 rails 命令又开始工作了。

bundle update bcrypt
Using bcrypt 3.1.13 (was 3.1.12)

希望这些提示对以后遇到此问题的任何人有所帮助!