LoginSignup
7
6

More than 5 years have passed since last update.

devise利用時の"cannot load such file -- bcrypt_ext"エラー対応

Last updated at Posted at 2017-12-11

"cannot load such file -- bcrypt_ext"で検索するとQiita内でも結構ヒットします。
たぶんWindows環境の人は必ず一度はぶち当たるのではないでしょうか。。。

他の方の投稿で解決できないパターンに遭遇したので記事を起こしました。

発生環境

Windows 10 64bit
Rails 5.1.4
Ruby 2.3.3p222[i386-mingw32]
devise 4.3
bcrypt 3.1.11

発生手順

deviseでユーザー登録ページまで作成、メールアドレス・パスワードを入力し、サインアップした瞬間以下エラーになりました。

devise.PNG

発生原因

以下リンクの@scivolaさんのコメントが非常に参考になります。
https://qiita.com/totto357/items/1741da83bf642dab99df#comment-4837bb466422937d7357

Gemfile.lockを見ると確かにbcrypt (3.1.11-x86-mingw32)があるので、これではRuby2.3.3では動かないのでしょう

対策

bcrypt-rubyを追加

Gemfileにgem 'bcrypt-ruby', '~> 3.0.0'を追記します。

Gemfile
gem 'bcrypt-ruby', '~> 3.0.0'

参考:https://qiita.com/uloruson/items/7b728b40a3abeb3128d0

Gemfile.lock
bcrypt (3.1.11-x86-mingw32)
bcrypt-ruby (3.0.1-x86-mingw32)

結果、上記2つのgemが追記されたがエラー解消せず

bcryptを追加

gem install bcrypt --platform=rubyを実行した後、Gemfileにgem 'bcrypt', '~> 3.1.11'を追記

Gemfile
gem 'bcrypt', '~> 3.1.11'

参考:https://qiita.com/totto357/items/1741da83bf642dab99df

Gemfile.lock
bcrypt (3.1.11-x86-mingw32)

結果、追加されたbcryptはx86-mingw32の為エラー解消せず

bcrypt-rubyをgitから追加

Gemfileにgem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', require: 'bcrypt'を追記

Gemfile
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', require: 'bcrypt'

参考:https://github.com/codahale/bcrypt-ruby/issues/142#issuecomment-350175740

Gemfile.lock
GIT
  remote: https://github.com/codahale/bcrypt-ruby.git
  revision: f2db689ba567d1a018f4dacb1ccf909adc93e887
  specs:
    bcrypt (3.1.11)

結果、無印のbcryptが追加され、エラー解消しました。

さいごに

エラー解決に2日かかりました。
Windowsもうヤダ

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6