错误:遇到未定义的提供者!通常这意味着你有一个循环依赖可能是由使用“桶” index.ts 文件引起的

问题描述

我不知道是什么导致了这个错误。当我运行 ionic server 命令时,它会显示以下运行时错误

Error: Encountered undefined provider! Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.
    at SyntaxError (http://192.168.0.115:8100/build/vendor.js:93699:34)
    at http://192.168.0.115:8100/build/vendor.js:108838:40
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver._getProvidersMetadata (http://192.168.0.115:8100/build/vendor.js:108823:19)
    at CompileMetadataResolver.getNgModuleMetadata (http://192.168.0.115:8100/build/vendor.js:108393:50)
    at JitCompiler._loadModules (http://192.168.0.115:8100/build/vendor.js:126717:87)
    at JitCompiler._compileModuleAndComponents (http://192.168.0.115:8100/build/vendor.js:126678:36)
    at JitCompiler.compileModuleAsync (http://192.168.0.115:8100/build/vendor.js:126594:37)
    at CompilerImpl.compileModuleAsync (http://192.168.0.115:8100/build/vendor.js:92535:49)
    at PlatformRef.bootstrapModule (http://192.168.0.115:8100/build/vendor.js:6107:25)
Ionic Framework: 3.9.2
Ionic App Scripts: 3.2.4
Angular Core: 5.0.0
Angular Compiler CLI: ^11.0.5
Node: 14.15.1
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/87.0.4280.88 Safari/537.36

在运行项目时遇到错误

解决方法

当您的代码的一部分依赖于第二段代码时,会抛出此错误,而第二段又依赖于第一段。这种情况的一个简单示例是,如果服务 A 调用服务 B 的函数,但该函数使用服务 A 中的代码。在 B 执行完毕之前,A 无法执行,但除非 A 执行完毕,否则 B 无法执行。因此称为循环依赖。

您提供的数据不足以分析问题。请分享更多。