运行 rake 任务时突然出现 "already initialized constant" 错误

Sudden "already initialized constant" errors when running rake tasks

我已经 运行 在 Windows 机器上完成 rake 任务一段时间没问题了。然后当我 运行 任何与佣金相关的事情时,我突然开始出现错误。它是在我 运行 rake db:migrate 之后第一次发生,我认为这可能是在我更改迁移之后没有先将其回滚之后发生的。现在,每个 rake 命令都会给出:

> rake db:rollback

c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: already initialized constant FileUtils::RUBY
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:10: warning: previous definition of RUBY was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: already initialized constant FileUtils::LN_SUPPORTED
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils.rb:109: warning: previous definition of LN_SUPPORTED was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils_ext.rb:17: warning: already initialized constant Rake::FileUtilsExt::DEFAULT
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_utils_ext.rb:17: warning: previous definition of DEFAULT was here
WARNING: Possible conflict with Rake extension: String#ext already exists
WARNING: Possible conflict with Rake extension: String#pathmap already exists
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:44: warning: already initialized constant Rake::FileList::ARRAY_METHODS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:44: warning: previous definition of ARRAY_METHODS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:47: warning: already initialized constant Rake::FileList::MUST_DEFINE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:47: warning: previous definition of MUST_DEFINE was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:51: warning: already initialized constant Rake::FileList::MUST_NOT_DEFINE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:51: warning: previous definition of MUST_NOT_DEFINE was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:55: warning: already initialized constant Rake::FileList::SPECIAL_RETURN
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:55: warning: previous definition of SPECIAL_RETURN was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:61: warning: already initialized constant Rake::FileList::DELEGATING_METHODS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:61: warning: previous definition of DELEGATING_METHODS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:86: warning: already initialized constant Rake::FileList::GLOB_PATTERN
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:86: warning: previous definition of GLOB_PATTERN was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:381: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PATTERNS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:381: warning: previous definition of DEFAULT_IGNORE_PATTERNS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:387: warning: already initialized constant Rake::FileList::DEFAULT_IGNORE_PROCS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/file_list.rb:387: warning: previous definition of DEFAULT_IGNORE_PROCS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:3: warning: already initialized constant Rake::VERSION
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:3: warning: previous definition of VERSION was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MAJOR
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of MAJOR was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::MINOR
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of MINOR was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::BUILD
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of BUILD was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: already initialized constant Rake::Version::OTHER
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:6: warning: previous definition of OTHER was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:8: warning: already initialized constant Rake::Version::NUMBERS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/version.rb:8: warning: previous definition of NUMBERS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/linked_list.rb:110: warning: already initialized constant Rake::LinkedList::EMPTY
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/linked_list.rb:110: warning: previous definition of EMPTY was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/scope.rb:41: warning: already initialized constant Rake::Scope::EMPTY
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/scope.rb:41: warning: previous definition of EMPTY was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/promise.rb:12: warning: already initialized constant Rake::Promise::NOT_SET
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/promise.rb:12: warning: previous definition of NOT_SET was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:13: warning: already initialized constant Rake::CommandLineOptionError
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:13: warning: previous definition of CommandLineOptionError was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:41: warning: already initialized constant Rake::Application::DEFAULT_RAKEFILES
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/application.rb:41: warning: previous definition of DEFAULT_RAKEFILES was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/task_arguments.rb:108: warning: already initialized constant Rake::EMPTY_TASK_ARGS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/task_arguments.rb:108: warning: previous definition of EMPTY_TASK_ARGS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/invocation_chain.rb:55: warning: already initialized constant Rake::InvocationChain::EMPTY
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/invocation_chain.rb:55: warning: previous definition of EMPTY was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/early_time.rb:21: warning: already initialized constant Rake::EARLY
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/early_time.rb:21: warning: previous definition of EARLY was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/late_time.rb:17: warning: already initialized constant Rake::LATE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/late_time.rb:17: warning: previous definition of LATE was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:4: warning: already initialized constant Rake::Backtrace::SYS_KEYS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:4: warning: previous definition of SYS_KEYS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:5: warning: already initialized constant Rake::Backtrace::SYS_PATHS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:5: warning: previous definition of SYS_PATHS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:8: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:8: warning: previous definition of SUPPRESSED_PATHS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:12: warning: already initialized constant Rake::Backtrace::SUPPRESSED_PATHS_RE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:12: warning: previous definition of SUPPRESSED_PATHS_RE was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:16: warning: already initialized constant Rake::Backtrace::SUPPRESS_PATTERN
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake/backtrace.rb:16: warning: previous definition of SUPPRESS_PATTERN was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:70: warning: already initialized constant FileList
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:70: warning: previous definition of FileList was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:71: warning: already initialized constant RakeFileUtils
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rake-12.3.0/lib/rake.rb:71: warning: previous definition of RakeFileUtils was here
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/load_error.rb:2: warning: already initialized constant LoadError::REGEXPS
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/load_error.rb:2: warning: previous definition of REGEXPS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/validations/clusivity.rb:6: warning: already initialized constant ActiveModel::Validations::Clusivity::ERROR_MESSAGE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/validations/clusivity.rb:6: warning: previous definition of ERROR_MESSAGE was here

我发现一些相关的线程说问题是我需要在命令之前输入 "bundle exec"。我以前从来没有这样做过,但我试过了。我得到了一个更短但相似的错误:

> bundle exec rake db:rollback

c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/load_error.rb:2: warning: already initialized constant LoadError::REGEXPS
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/activesupport-5.1.4/lib/active_support/core_ext/load_error.rb:2: warning: previous definition of REGEXPS was here
c:/ruby24-x64/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/validations/clusivity.rb:6: warning: already initialized constant ActiveModel::Validations::Clusivity::ERROR_MESSAGE
c:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/activemodel-5.1.4/lib/active_model/validations/clusivity.rb:6: warning: previous definition of ERROR_MESSAGE was here

有人知道是什么原因造成的吗?


更新

出于某种原因,我的计算机对 Ruby 的位置感到困惑,所以我不得不在本地而不是像这样在全球范围内重新安装所有内容:

bundle install --path vendor/cache

出于某种原因,我的服务器对我的 Ruby 文件夹的大小写感到困惑,似乎认为有两个,尽管实际上没有。我必须在我的应用程序中本地而不是全局重新安装所有内容,如下所示:

bundle install --path vendor/cache

它现在可以正常工作,没有任何警告。