将 Bundler 升级到 2.1.4 后初始化 Rails 控制台出错

Posted

技术标签:

【中文标题】将 Bundler 升级到 2.1.4 后初始化 Rails 控制台出错【英文标题】:Error initializing Rails console after upgrading Bundler to 2.1.4 【发布时间】:2020-11-26 21:50:09 【问题描述】:

这只发生在 Elastic Beanstalk 机器上,我在本地初始化 rails 控制台时没有问题。

我们刚刚从 1.17.3 升级到 Bundler 2.1.4

用于在我们的 EB 机器上运行 rails 控制台的脚本:

#!/usr/bin/env bash
#
# Rails console script that can be run on AWS Elastic Beanstalk.

set -xe

EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_deploy_dir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config container -k app_user)
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
EB_PID_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_pid_dir)
EB_LOG_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_log_dir)

. $EB_SUPPORT_DIR/envvars

. $EB_SCRIPT_DIR/use-app-ruby.sh

cd $EB_APP_DEPLOY_DIR

su -s /bin/bash -c "bundle exec rails c" $EB_APP_USER

这是运行所述脚本的输出:

Bundler will use `/tmp/bundler20200806-29516-1noiblx29516' as your home directory temporarily.
/opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/ftp.rb:23:in `<module:URI>': /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:99: warning: already initialized constant URI::VERSION_CODE
/opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:99: warning: previous definition of VERSION_CODE was here
/opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:100: warning: already initialized constant URI::VERSION
/opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:100: warning: previous definition of VERSION was here
uninitialized constant URI::Generic (NameError)
Did you mean?  URI::Generic
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/ftp.rb:13:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:107:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri.rb:107:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/rfc2396_parser.rb:13:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/rfc2396_parser.rb:13:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/common.rb:13:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/common.rb:13:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/generic.rb:12:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/2.4.0/uri/generic.rb:12:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object/json.rb:6:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object/json.rb:6:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object.rb:13:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/core_ext/object.rb:13:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/configuration.rb:4:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/configuration.rb:4:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/railtie/configuration.rb:3:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/railtie/configuration.rb:3:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/railtie.rb:223:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/railtie.rb:223:in `config'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/railtie.rb:127:in `config'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/i18n_railtie.rb:11:in `<class:Railtie>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/i18n_railtie.rb:10:in `<module:I18n>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/i18n_railtie.rb:9:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/railtie.rb:4:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/activesupport-5.2.3/lib/active_support/railtie.rb:4:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails.rb:17:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails.rb:17:in `<top (required)>'
    from /var/app/current/config/application.rb:3:in `require'
    from /var/app/current/config/application.rb:3:in `<top (required)>'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/command/actions.rb:22:in `require'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/command/actions.rb:22:in `require_application!'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/commands/console/console_command.rb:95:in `perform'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/command.rb:27:in `run'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor/invocation.rb:126:in `invoke_command'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/thor-0.19.4/lib/thor.rb:369:in `dispatch'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
    from /opt/rubies/ruby-2.4.3/lib/ruby/gems/2.4.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
    from bin/rails:9:in `require'
    from bin/rails:9:in `<main>'

尝试执行bundle clean --force 并将require 'uri' 添加到application.rb 失败

感谢任何提示!谢谢。

【问题讨论】:

【参考方案1】:

我们找不到解决方法,所以我们最终降级到 1.17.4!

【讨论】:

以上是关于将 Bundler 升级到 2.1.4 后初始化 Rails 控制台出错的主要内容,如果未能解决你的问题,请参考以下文章

将 Rails 6 应用程序部署到 Elastic Beanstalk 时出现 Bundler 错误

乘客错误在 Bluehost 共享主机上的任何源 (Bundler::GemNotFound) 中找不到 rake-11.3.0

Rails 3 rc 上的 Macvim 和 rails.vim - 未初始化的常量 Bundler (NameError)

pg gem 安装错误 - lion osx、bundler 和 rvm

如何降级捆绑器或升级导轨?

Metro bundler 在“加载依赖图,完成”后停止