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

问题描述 投票:0回答:1

下面的 Ruby 脚本在需要

LoadError
gem 时给了我一个
activesupport
,但其他所有内容都显示它已安装。无论我通过
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
  • 红宝石 3.1.2p20
  • 宝石3.3.7
  • 捆绑包 2.3.7
  • macOS 13.5.2 (M2)
ruby rubygems bundler rvm ruby-3
1个回答
0
投票

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

require "active_support"

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

© www.soinside.com 2019 - 2024. All rights reserved.