Rails 7 Ruby 3.1 LoadError: cannot load such file -- net/smtp
Rails 7 Ruby 3.1 LoadError: cannot load such file -- net/smtp
我升级到 Rails 7 和 Ruby 3.1。在尝试使用 rspec
进行 运行 测试时,出现以下错误。我该如何解决?
An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../config/environment', __dir__)
LoadError:
cannot load such file -- net/smtp
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../gems/mail-2.7.1/lib/mail.rb:9:in `<module:Mail>'
# .../gems/mail-2.7.1/lib/mail.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox/mail_ext.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox/engine.rb:9:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# ./config/application.rb:11:in `<top (required)>'
# ./config/environment.rb:2:in `require_relative'
# ./config/environment.rb:2:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
No examples found.
Finished in 0.00005 seconds (files took 0.57758 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
UPD: 2022 年 1 月 6 日 Rails 7.0.1 是 released:
The focus of this release is bring support to Ruby 3.1
在其他 Ruby 3.1 相关问题中,它为这个问题带来了 a fix。所以 升级到 Rails >= 7.0.1.
将 gem 'net-smtp', require: false
添加到您的 Gemfile 和 运行 bundle
.
同样,我假设您可能在 net-imap
和 net-pop
方面遇到问题,因此必须添加它们 until 发布了新的 mail
gem 版本.
相关拉取请求和问题:
我在生产模式下 运行 Rails 遇到了同样的问题。 ( Ruby 3, Rails 6.1 )
将这行代码复制并粘贴到 Gemfile
:
gem 'net-smtp', require: false
gem 'net-imap', require: false
gem 'net-pop', require: false
我升级到 Rails 7 和 Ruby 3.1。在尝试使用 rspec
进行 运行 测试时,出现以下错误。我该如何解决?
An error occurred while loading rails_helper.
Failure/Error: require File.expand_path('../config/environment', __dir__)
LoadError:
cannot load such file -- net/smtp
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:34:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../gems/mail-2.7.1/lib/mail.rb:9:in `<module:Mail>'
# .../gems/mail-2.7.1/lib/mail.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox/mail_ext.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox.rb:3:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# .../bundler/gems/rails-6a0f6c4d70b1/actionmailbox/lib/action_mailbox/engine.rb:9:in `<main>'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:in `register'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
# .../gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
# .../gems/zeitwerk-2.5.2/lib/zeitwerk/kernel.rb:36:in `require'
# ./config/application.rb:11:in `<top (required)>'
# ./config/environment.rb:2:in `require_relative'
# ./config/environment.rb:2:in `<top (required)>'
# ./spec/rails_helper.rb:4:in `require'
# ./spec/rails_helper.rb:4:in `<top (required)>'
No examples found.
Finished in 0.00005 seconds (files took 0.57758 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
UPD: 2022 年 1 月 6 日 Rails 7.0.1 是 released:
The focus of this release is bring support to Ruby 3.1
在其他 Ruby 3.1 相关问题中,它为这个问题带来了 a fix。所以 升级到 Rails >= 7.0.1.
将 gem 'net-smtp', require: false
添加到您的 Gemfile 和 运行 bundle
.
同样,我假设您可能在 net-imap
和 net-pop
方面遇到问题,因此必须添加它们 until 发布了新的 mail
gem 版本.
相关拉取请求和问题:
我在生产模式下 运行 Rails 遇到了同样的问题。 ( Ruby 3, Rails 6.1 )
将这行代码复制并粘贴到 Gemfile
:
gem 'net-smtp', require: false
gem 'net-imap', require: false
gem 'net-pop', require: false