参数错误(模块树中已删除Api::V1的副本,但仍处于活动状态!)

7

我已经为此问题苦苦挣扎了好几天。我正在构建一些API的应用程序,但当首次运行时,上述错误总是会导致我的应用程序崩溃。重新加载应用程序后错误就消失了,但仍然很烦人。以下是关于此错误的一些类似问题:

A copy of xxx has been removed from the module tree but is still active

ArgumentError: A copy of ApplicationController has been removed from the module tree but is still active

这两个链接都没有解决我所面临的问题。以下是完整的堆栈跟踪信息:

ArgumentError (A copy of Api::V1 has been removed from the module tree but is still active!):
activesupport (5.1.4) lib/active_support/dependencies.rb:495:in `load_missing_constant'
activesupport (5.1.4) lib/active_support/dependencies.rb:202:in `const_missing'
activesupport (5.1.4) lib/active_support/inflector/methods.rb:271:in `const_get'
activesupport (5.1.4) lib/active_support/inflector/methods.rb:271:in `block in constantize'
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `each'
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `inject'
activesupport (5.1.4) lib/active_support/inflector/methods.rb:267:in `constantize'
activesupport (5.1.4) lib/active_support/dependencies.rb:582:in `get'
activesupport (5.1.4) lib/active_support/dependencies.rb:613:in `constantize'
actionpack (5.1.4) lib/action_dispatch/http/request.rb:85:in `controller_class_for'
actionpack (5.1.4) lib/action_dispatch/http/parameters.rb:99:in `binary_params_for?'
actionpack (5.1.4) lib/action_dispatch/http/parameters.rb:90:in `set_binary_encoding'
actionpack (5.1.4) lib/action_dispatch/http/parameters.rb:67:in `path_parameters='
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:48:in `block in serve'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `each'
actionpack (5.1.4) lib/action_dispatch/journey/router.rb:33:in `serve'
actionpack (5.1.4) lib/action_dispatch/routing/route_set.rb:834:in `call'
bullet (5.7.5) lib/bullet/rack.rb:14:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/cookies.rb:613:in `call'
activerecord (5.1.4) lib/active_record/migration.rb:556:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
activesupport (5.1.4) lib/active_support/callbacks.rb:97:in `run_callbacks'
actionpack (5.1.4) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
airbrake (7.3.0) lib/airbrake/rack/middleware.rb:52:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
web-console (3.6.1) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.6.1) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.6.1) lib/web_console/middleware.rb:20:in `catch'
web-console (3.6.1) lib/web_console/middleware.rb:20:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
railties (5.1.4) lib/rails/rack/logger.rb:36:in `call_app'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `block in call'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `block in tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (5.1.4) lib/active_support/tagged_logging.rb:69:in `tagged'
railties (5.1.4) lib/rails/rack/logger.rb:24:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/request_id.rb:25:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.1.4) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (5.1.4) lib/action_dispatch/middleware/static.rb:125:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
rack-mini-profiler (1.0.0) lib/mini_profiler/profiler.rb:285:in `call'
webpacker (3.4.3) lib/webpacker/dev_server_proxy.rb:18:in `perform_request'
rack-proxy (0.6.4) lib/rack/proxy.rb:57:in `call'
railties (5.1.4) lib/rails/engine.rb:522:in `call'
puma (3.11.4) lib/puma/configuration.rb:225:in `call'
puma (3.11.4) lib/puma/server.rb:632:in `handle_request'
puma (3.11.4) lib/puma/server.rb:446:in `process_client'
puma (3.11.4) lib/puma/server.rb:306:in `block in run'
puma (3.11.4) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
1个回答

8
根据堆栈跟踪显示,这是应用程序与ActiveSupport存在依赖冲突。我建议使用gem bootsnap。Bootsnap覆盖了ActiveSupport::Dependencies,这正是引起问题的原因。它还可以提高应用程序的加载时间,这实际上也是它的设计目的。从Bootsnap文档中可以看到:

覆盖了ActiveSupport::Dependencies.{autoloadable_module?,load_missing_constant,depend_on},以消除对ActiveSupport::Dependencies.autoload_paths的扫描。


因为在 bootsnap gem 中遵循所有指示后,该问题现在出现在应用程序中,所以重新启用此功能。您似乎通过挖掘解决了这个问题。您能分享一些见解吗? - Derrell Durrett
@DerrellDurrett 对不起,这是很久以前的事情了,只是使用 bootsnap 解决了我的问题。从那以后我再也没有遇到过这个问题。也许 https://dev59.com/B10b5IYBdhLWcg3wEdsx 可以帮助你。 - UsamaMan
这可能就是问题所在了,虽然循环依赖的具体情况可能不同。如果这仍然是个问题,我想我知道该看什么了... - Derrell Durrett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接