轨道上的“Zeitwerk::SetupRequired”错误。是什么意思?

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

我在浏览本地运行的 Rails 应用程序时收到错误 “Zeitwerk::SetupRequired:请完成配置并在一切准备就绪后调用 Zeitwerk::Loader#setup”。 (Rails v6.0.6)

这是什么意思以及如何解决它?

应用程序仅部分损坏。这有点突然。我一直在搞乱一些东西,但它是在一个以前运行良好的应用程序上的。

我首先在谷歌上搜索 Zeitwerk 是什么:-) 所以我认为我在“加载”一些 Rails 代码时遇到了问题。

我尝试运行

rails zeitwerk:check
给出如下输出:

Sidekiq 7.0
Hold on, I am eager loading the application.

WARNING: The following directories will only be checked if you configure
them to be eager loaded:

  /path/to/my/rails/app/lib
  /path/to/my/rails/app/mailer_previews

You may verify them manually, or add them to config.eager_load_paths
in config/application.rb and run zeitwerk:check again.

Otherwise, all is good!

这似乎是相当正常的输出(例如,它符合本指南显示的内容

ruby-on-rails zeitwerk
2个回答
0
投票

重新启动rails应用程序服务器即可修复它!

我已经很好地运行了,没有费心重新启动我的本地应用程序服务器,所以我花了太长时间才想到这样做,但显然,如果 Rails 的内裤与任何与“加载”相关的东西发生了扭曲代码(这就是 Zeitwerk 的全部内容),那么这应该是首先要尝试的事情。


0
投票

我自己也遇到过一两次这个错误 - 每次运行

rails zeitwerk:check
(正如你提到的),它都得到了解决,更重要的是,按照检查点进行操作😉

哪个 - 在本例中是在编辑器中打开

config/application.rb
并确保它具有以下内容:

require_relative "boot"

require "rails/all"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Src
  class Application < Rails::Application
    ...
    # config.eager_load_paths << Rails.root.join("extras")
    config.eager_load_paths << "#{root}/app/lib"
    config.eager_load_paths << "#{root}/app/mailer_previews"
    ...
  end
end


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