无法加载此类文件--bcrypt_ext

时间:2017-01-12 19:08:13

标签: ruby-on-rails ruby devise bcrypt

我正在使用Devise for Rails 5.0.1时遇到bcrypt加密器的故障。我之前从未遇到过这个问题,早期的Rails 4.2。我无法通过Devise注册新用户。我将发布有关我的gemfile和服务器日志的信息。

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'

服务器日志

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

5 个答案:

答案 0 :(得分:9)

今天我遇到了类似的问题,包括ruby 2.3.3和rails 4.2.4。

问题在于bundle install设计作为依赖项安装了另一个版本的bcrypt(bcrypt (3.1.11 x86-mingw32)而不是bcrypt (3.1.11)),这导致了ruby 2.3的问题(它应该适用于以前的所有版本)版本的红宝石)

我使用的解决方案是在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)

希望如果你还没有解决问题,这会有所帮助。

答案 1 :(得分:4)

我也遇到了同样的问题,然后我找到了一些参考资料,它只是关于版本的。

当我将bcrypt改回

bcrypt 3.1.0-x86-mingw32

来自

bcrypt 3.1.11-x86-mingw32(the latest now)

然后再次确认gemfile

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

然后它运作正常。

答案 2 :(得分:1)

对于ruby' 2.3.3 '和rails' 5.2.0 ',我也面临同样的问题,但现在唯一的解决方案是运行:

gem uninstall bcrypt
gem install bcrypt --platform=ruby

临时修复。

答案 3 :(得分:0)

可能只是本机二进制文件被错误地构建或损坏。请尝试以下

  1. 打开命令控制台
  2. cd到gem目录C:\ RailsInstaller \ Ruby2.2.0 \ lib \ ruby​​ \ gems \ 2.2.0 \ gems \ bcrypt-3.1.10-x86-mingw32 \ ext \ mri
  3. 运行ruby extconf.rb。它应该创建Makefile
  4. 运行make。它将构建扩展库。
  5. 运行make install
  6. Fix issue "cannot load such file -- bcrypt_ext (LoadError)"

    了解详情

答案 4 :(得分:0)

修复MS Win 10和8中的问题的这些步骤

  1. 卸载所有bcrypt

    gem uninstall bcrypt
    
  2. 继续使用lib / ruby​​ / gems / 2.3.0 / gems / bcrypt-3.1.11-x86-mingw32 / lib /并复制bcrypt_ext.so文件。并暂时粘贴在桌面上。

  3. 再次卸载所有bcrypt

    gem uninstall bcrypt 
    
  4. 添加项目的gemfile

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

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

  7. 重启服务器

    rails server
    
  8. 它适用于胜利7和10 !!!