在Ruby 3中使用bundle exec运行脚本时发生LoadError(使用rvm)

zed5wv10  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(99)

下面的Ruby脚本在需要activesupport gem时给了我一个LoadError,但其他所有东西都显示它已经安装。无论我是通过bundle exec还是rvm do运行它,都会得到相同的错误。

$ cat Gemfile | grep activesupport
gem 'activesupport'

$ bundle show activesupport
/Users/2b-software-mac/.rvm/gems/ruby-3.1.2/gems/activesupport-7.0.6

$ bundle exec ruby my_ruby_script.rb
Can I find the gem?
#<Bundler::StubSpecification name=activesupport version=7.0.6 platform=ruby>
Can I require the gem?
my_ruby_script.rb:4:in `require': cannot load such file -- activesupport (LoadError)
    from my_ruby_script.rb:4:in `<main>'

脚本

puts 'Can I find the gem?'
puts Gem::Specification.find_all{ |g| g.name.include? 'activesupport' }
puts 'Can I require the gem?'
require 'activesupport'

版本

  • rvm 1.29.12
  • ruby 3.1.2p20
  • gem 3.3.7
  • 捆绑包2.3.7
  • macOS 13.5.2(M2)
igsr9ssn

igsr9ssn1#

gem必须像这样加载(注意下划线):

require "active_support"

阅读Rails指南中的独立主动支持。

相关问题