首页 > 解决方案 > Webpacker 安装给出错误:无法加载此类文件 — ubygems

问题描述

我在 rvm 和 nodejs15 下的 OS X 11.2.3 和 ruby​​ 3.0.1、rails 6.1.3.2 上运行(但我也用 ruby​​ 2.7.2 和 2.5 试过这个,我试过用内置的 ruby​​ 和 macports包括删除每个非系统 ruby​​ 文件并重新安装 ruby​​ 和节点),每次我使用 rails new 或尝试运行命令 rails webpacker:install 时都会出现以下错误。

/Users/TruePath/Documents/Projects/math-site/bin/rails:in `require': 无法加载此类文件 -- ubygems (LoadError)

我尝试过创建没有链轮、没有弹簧的项目,并且我已经检查过 yarn 是正确的版本。我已经包含了当我在下面运行命令时生成的消息。

请帮助我现在花了整整 2 天的时间试图在没有运气的情况下找到它!请注意,不是 nodejs 警告的不稳定版本,因为我浪费了很多时间来撕掉 nodejs 的任何提示并重新安装稳定版本而没有运气。

ruby --verbose bin/rails webpacker:install
/usr/local/rvm/gems/ruby-3.0.1/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:49: warning: method redefined; discarding old require_relative
/usr/local/rvm/gems/ruby-3.0.1/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:57: warning: method redefined; discarding old load
/usr/local/rvm/gems/ruby-3.0.1/gems/sassc-rails-2.1.2/lib/sassc/rails/functions.rb:7: warning: method redefined; discarding old asset_data_url
/usr/local/rvm/gems/ruby-3.0.1/gems/sprockets-4.0.2/lib/sprockets/sass_processor.rb:274: warning: previous definition of asset_data_url was here
/usr/local/rvm/gems/ruby-3.0.1/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:7: warning: method redefined; discarding old initialize
/usr/local/rvm/gems/ruby-3.0.1/gems/sprockets-4.0.2/lib/sprockets/sass_compressor.rb:39: warning: previous definition of initialize was here
/usr/local/rvm/gems/ruby-3.0.1/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:17: warning: method redefined; discarding old call
/usr/local/rvm/gems/ruby-3.0.1/gems/sprockets-4.0.2/lib/sprockets/sass_compressor.rb:49: warning: previous definition of call was here
/usr/local/rvm/gems/ruby-3.0.1/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:23: warning: method redefined; discarding old require
/usr/local/rvm/gems/ruby-3.0.1/gems/bootsnap-1.7.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:27: warning: previous definition of require was here
Warning: you are using an unstable release of Node.js (v15.14.0). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node
/Users/TruePath/Documents/Projects/math-site/bin/rails:in `require': cannot load such file -- ubygems (LoadError)

标签: ruby-on-railsruby-on-rails-6webpacker

解决方案


看来这个错误是由我的 bashrc 设置 RUBYOPT=rubygems 引起的,这似乎导致代码问题的奇怪混合。不知道如何或为什么,但这似乎是问题所在,所以也许这将帮助其他人避免很多痛苦和痛苦,试图自己追赶它。


推荐阅读