简体   繁体   English

无法加载此类文件--bcrypt_ext

[英]Cannot load such file — bcrypt_ext

I'm currently experiencing the failure of bcrypt's encryptor while using Devise for Rails 5.0.1. 我正在使用Devise for Rails 5.0.1时遇到bcrypt的加密器失败。 I never had this issue before with the earlier Rails 4.2. 我之前从未遇到过这个问题,早期的Rails 4.2。 I can't register new users through Devise. 我无法通过Devise注册新用户。 I will post information with regards to my gemfile and server log. 我将发布有关我的gemfile和服务器日志的信息。

Gemfile.rb Gemfile.rb

gem 'bcrypt', platforms: :ruby

# Devise
gem 'devise'
gem 'devise_security_extension'

gem 'redis'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.1'

Server log 服务器日志

Started POST "/register" for 127.0.0.1 at 2017-01-12 13:50:05 -0500
Processing by Users::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"bH6n7iWLhPMECDzTVkMyTc9FXtvkGrq5+K4wFs1g8Bxbjq9ShaLJP5gn72SFQlHc01j2ao5JKcv57ClWAzwsmw==", "user"=>{"email"=>"craigcarl@codex.com", "username"=>"codex", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Completed 500 Internal Server Error in 258ms (ActiveRecord: 0.0ms)



LoadError - cannot load such file -- bcrypt_ext:
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  bcrypt-3.1.11-x86 (mingw32) lib/bcrypt.rb:16:in `rescue in <top (required)>'
  bcrypt-3.1.11-x86 (mingw32) lib/bcrypt.rb:12:in `<top (required)>'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  devise (4.2.0) lib/devise/encryptor.rb:1:in `<top (required)>'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `block in require'
  activesupport (5.0.1) lib/active_support/dependencies.rb:259:in `load_dependency'
  activesupport (5.0.1) lib/active_support/dependencies.rb:293:in `require'
  devise (4.2.0) lib/devise/models/database_authenticatable.rb:147:in `password_digest'
  devise (4.2.0) lib/devise/models/database_authenticatable.rb:40:in `password='
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:46:in `public_send'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:46:in `_assign_attribute'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:40:in `block in _assign_attributes'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:39:in `each'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:39:in `_assign_attributes'
  activerecord (5.0.1) lib/active_record/attribute_assignment.rb:26:in `_assign_attributes'
  activemodel (5.0.1) lib/active_model/attribute_assignment.rb:33:in `assign_attributes'
  activerecord (5.0.1) lib/active_record/core.rb:319:in `initialize'
  activerecord (5.0.1) lib/active_record/inheritance.rb:65:in `new'
  activerecord (5.0.1) lib/active_record/inheritance.rb:65:in `new'
  devise (4.2.0) lib/devise/models/registerable.rb:20:in `new_with_session'
  devise (4.2.0) app/controllers/devise/registrations_controller.rb:100:in `build_resource'
  devise (4.2.0) app/controllers/devise/registrations_controller.rb:15:in `create'
  actionpack (5.0.1) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
  actionpack (5.0.1) lib/abstract_controller/base.rb:188:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (5.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (5.0.1) lib/active_support/callbacks.rb:126:in `call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
  activesupport (5.0.1) lib/active_support/callbacks.rb:455:in `call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:101:in `__run_callbacks__'
  activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
  activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/rescue.rb:20:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (5.0.1) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (5.0.1) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
  activesupport (5.0.1) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (5.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (5.0.1) lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
  activerecord (5.0.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (5.0.1) lib/abstract_controller/base.rb:126:in `process'
  actionview (5.0.1) lib/action_view/rendering.rb:30:in `process'
  actionpack (5.0.1) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (5.0.1) lib/action_controller/metal.rb:262:in `dispatch'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
  actionpack (5.0.1) lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
  actionpack (5.0.1) lib/action_dispatch/routing/mapper.rb:46:in `serve'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `each'
  actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `serve'
  actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call'
  rack (2.0.1) lib/rack/deflater.rb:35:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `catch'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  rack (2.0.1) lib/rack/etag.rb:25:in `call'
  rack (2.0.1) lib/rack/conditional_get.rb:38:in `call'
  rack (2.0.1) lib/rack/head.rb:12:in `call'
  rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context'
  rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
  activerecord (5.0.1) lib/active_record/migration.rb:553:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
  activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
  activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
  activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
  actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
  web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app'
  web-console (3.4.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (3.4.0) lib/web_console/middleware.rb:18:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
  railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app'
  railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged'
  railties (5.0.1) lib/rails/rack/logger.rb:24:in `call'
  sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
  rack (2.0.1) lib/rack/method_override.rb:22:in `call'
  rack (2.0.1) lib/rack/runtime.rb:22:in `call'
  activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
  actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
  rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
  railties (5.0.1) lib/rails/engine.rb:522:in `call'
  puma (3.6.2) lib/puma/configuration.rb:225:in `call'
  puma (3.6.2) lib/puma/server.rb:578:in `handle_request'
  puma (3.6.2) lib/puma/server.rb:415:in `process_client'
  puma (3.6.2) lib/puma/server.rb:275:in `block in run'
  puma (3.6.2) lib/puma/thread_pool.rb:116:in `block in spawn_thread'

Started POST "/__better_errors/4e4442c3f810d7b9/variables" for 127.0.0.1 at 2017-01-12 13:50:06 -0500

I had a similar problem today with ruby 2.3.3 and rails 4.2.4. 我今天遇到类似问题的ruby 2.3.3和rails 4.2.4。

The problem was that bundle install of devise installed as a dependency another version of bcrypt ( bcrypt (3.1.11 x86-mingw32) instead of bcrypt (3.1.11) ) which was causing trouble with ruby 2.3 (it should work with all previous versions of ruby) 问题是bundle install的设备作为依赖安装另一个版本的bcrypt( bcrypt (3.1.11 x86-mingw32)而不是bcrypt (3.1.11) )这导致了ruby 2.3的问题(它应该适用于所有以前的版本红宝石)

The solution I used is to install bcrypt outside of the gemfile, run bundle and then remove the second version of bcrypt : 我使用的解决方案是在gemfile外部安装bcrypt,运行bundle然后删除第二个版本的bcrypt:

$ gem list bcrypt
bcrypt (3.1.11 x86-mingw32)

$ gem uninstall devise && gem uninstall bcrypt
Successfully uninstalled devise-4.2.0
Successfully uninstalled bcrypt-3.1.11-x86-mingw32

$ gem install bcrypt --platform=Ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed bcrypt-3.1.11
Parsing documentation for bcrypt-3.1.11
Installing ri documentation for bcrypt-3.1.11
Done installing documentation for bcrypt after 1 seconds
1 gem installed

$ gem list bcrypt
bcrypt (3.1.11)

$ bundle install
...
Installing bcrypt 3.1.11 (x86-mingw32)
...
Installing devise 4.2.0
Bundle complete! 25 Gemfile dependencies, 75 gems now installed.

$ gem list bcrypt
bcrypt (3.1.11 ruby x86-mingw32)

$ gem uninstall bcrypt
Select gem to uninstall:
 1. bcrypt-3.1.11
 2. bcrypt-3.1.11-x86-mingw32
 3. All versions
> 2
Successfully uninstalled bcrypt-3.1.11-x86-mingw32

$ gem list bcrypt
bcrypt (3.1.11)

Hope that helps if you haven't solved your problem yet. 如果你还没有解决问题,希望有所帮助。

I also encountered the same problem, then I found some references and it's about version only. 我也遇到了同样的问题,然后我找到了一些引用,它只是版本。

When I changed bcrypt back to 当我把bcrypt改回来的时候

bcrypt 3.1.0-x86-mingw32

from

bcrypt 3.1.11-x86-mingw32(the latest now)

Then make sure again in gemfile 然后在gemfile中再次确认

gem 'bcrypt-ruby', '3.1.0', :require => 'bcrypt'

then it works fine. 然后它工作正常。

I also face this same issue for ruby ' 2.3.3 ' and rails ' 5.2.0 ' but the only solution right now is to run: 对于ruby'2.3.3 '和rails'5.2.0 '我也面临同样的问题,但现在唯一的解决方案是运行:

gem uninstall bcrypt
gem install bcrypt --platform=ruby

temporary fix. 临时修复。

Maybe it's just the native binary is wrongly built or corrupted. 也许只是本机二进制文件被错误地构建或损坏。 Try below 试试以下

  1. Open a command console 打开命令控制台
  2. cd to the gem directory C:\\RailsInstaller\\Ruby2.2.0\\lib\\ruby\\gems\\2.2.0\\gems\\bcrypt-3.1.10-x86-mingw32\\ext\\mri cd到gem目录C:\\ RailsInstaller \\ Ruby2.2.0 \\ lib \\ ruby​​ \\ gems \\ 2.2.0 \\ gems \\ bcrypt-3.1.10-x86-mingw32 \\ ext \\ mri
  3. Run ruby extconf.rb. 运行ruby extconf.rb。 It should create the Makefile 它应该创建Makefile
  4. Run make. 运行make。 It will builde the extension libraries. 它将构建扩展库。
  5. Run make install 运行make install

See more at Fix issue "cannot load such file -- bcrypt_ext (LoadError)" 查看更多修复问题“无法加载此类文件--bcrypt_ext(LoadError)”

These steps to fix issue in MS Win 10 and 8 这些步骤可以解决MS Win 10和8中的问题

  1. Uninstall all bcrypt 卸载所有bcrypt

     gem uninstall bcrypt 
  2. Go on lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/ and copy bcrypt_ext.so file. 继续使用lib / ruby​​ / gems / 2.3.0 / gems / bcrypt-3.1.11-x86-mingw32 / lib /并复制bcrypt_ext.so文件。 and paste on desktop for now. 并暂时粘贴在桌面上。

  3. Uninstall all bcrypt again 再次卸载所有bcrypt

     gem uninstall bcrypt 
  4. Add in your project's gemfile 添加项目的gemfile

     gem 'bcrypt', '~> 3.1.7' 
  5. Run commands 运行命令

     bundle install bundle update 
  6. Paste copied bcrypt_ext.so in folder lib/ruby/gems/2.3.0/gems/bcrypt-3.1.11-x86-mingw32/lib/ from desktop. 将复制的bcrypt_ext.so粘贴到文件夹lib / ruby​​ / gems / 2.3.0 / gems / bcrypt-3.1.11-x86-mingw32 / lib /中。

  7. Restart server 重启服务器

     rails server 

It works on win 7 and 10!!! 它在7和10胜利!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM