我有一个问题,因为我的应用程序被迁移到角12。
我的应用程序启动时没有出错。打开某些页面时,我会得到以下错误:
core.js:6498 ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded.
If you need access to common directives such as NgIf and NgFor from a lazy loaded module,
import CommonModule instead.
Error: BrowserModule has already been loaded. If you need access to common directives such as
NgIf and NgFor from a lazy loaded module, import CommonModule instead.
at new BrowserModule (platform-browser.js:1527:1)
at Object.BrowserModule_Factory [as factory] (platform-browser.js:1549:58)
at R3Injector.hydrate (core.js:11457:1)
at R3Injector.get (core.js:11276:1)
at core.js:11314:1
at Set.forEach (<anonymous>)
at R3Injector._resolveInjectorDefTypes (core.js:11314:1)
at new NgModuleRef$1 (core.js:25345:1)
at NgModuleFactory$1.create (core.js:25399:1)
at MapSubscriber.project (router.js:3680:1)
at resolvePromise (zone.js:1213:1)
at resolvePromise (zone.js:1167:1)
at zone.js:1279:1
at ZoneDelegate.invokeTask (zone.js:406:1)
at Object.onInvokeTask (core.js:28679:1)
at ZoneDelegate.invokeTask (zone.js:405:1)
at Zone.runTask (zone.js:178:1)
at drainMicroTaskQueue (zone.js:582:1)
我在互联网上搜索了很多,我检查了我的应用程序只在App.module.ts
中加载了一次App.module.ts
(与BrowserAnimationsModule
一起)。
我注意到错误页只是那些使用延迟加载的页面。没有延迟加载而声明的路由是可用的。
我认为问题可能是一个已经加载BrowserModule
的外部包。但我没拿到身份证。我的package.json
:
"@angular/animations": "12.2.16",
"@angular/common": "12.2.16",
"@angular/compiler": "12.2.16",
"@angular/core": "12.2.16",
"@angular/forms": "12.2.16",
"@angular/platform-browser": "12.2.16",
"@angular/platform-browser-dynamic": "12.2.16",
"@angular/router": "12.2.16",
"@ng-select/ng-select": "^7",
"angular2-ie9-shims": "0.0.2",
"angular2-notifications": "12.0.0",
"chart.js": "^2.7.2",
"chartjs-plugin-datalabels": "^0.7.0",
"core-js": "2.5.4",
"exceljs": "1.10.0",
"file-saver": "1.3.8",
"flatpickr": "4.6.3",
"font-awesome": "4.7.0",
"geojson": "0.5.0",
"innersvg-polyfill": "0.0.2",
"jquery": "^3.4.1",
"jspdf": "^1.5.3",
"jszip": "3.1.5",
"karma-scss-preprocessor": "^4.0.0",
"leaflet": "1.3.4",
"leaflet-image": "^0.4.0",
"lodash": "4.17.11",
"moment": "2.29.1",
"moment-range": "^4.0.2",
"moment-timezone": "^0.5.25",
"ng-click-outside": "5.3.0",
"ng-recaptcha": "^8.0.1",
"ng2-dnd": "^5.0.2",
"ng2-file-upload": "1.4.0",
"ng2-validation": "4.2.0",
"ngx-bootstrap": "6.2.0",
"popper.js": "^1.15.0",
"rxjs": "^6.5.3",
"rxjs-compat": "6.3.2",
"smoothscroll-polyfill": "0.4.3",
"swiper": "^4.5.0",
"tablesorter": "^2.31.1",
"tooltip.js": "^1.3.1",
"tslib": "^2.0.0",
"web-animations-js": "^2.3.2",
"zone.js": "~0.11.4"
我还试图从BrowserAnimationsModule
中完全删除App.module.ts
。错误仍然存在。
我还在我的项目中搜索了AppModule
,它只存在于main.ts
中:
platformBrowserDynamic().bootstrapModule(AppModule).catch((err) => console.log(err));
我再也不知道该去哪里找了。你看到我给我其他的研究途径了吗?谢谢。
编辑
这个模块是延迟加载的,它会触发错误。
@NgModule({
imports: [
CommonModule,
AfpDatatableModule,
AfpCommonModule,
AfpSponsorDetectionRoutingModule,
DatalistModule,
AfpChartsModule
],
declarations: [
SponsorDetectionComponent,
SponsorDetectionFormComponent,
MultiBarChartGenericComponent,
SponsorDetectionTableComponent,
SuspectedRoamingCoherenceComponent
]
})
export class AfpSponsorDetectionModule {}
发布于 2022-02-22 11:19:50
从角度文献来看:
BrowserModule的提供者是整个应用程序的提供者,所以它应该只在根模块中,而不是在功能模块中。功能模块只需要CommonModule中的通用指令;它们不需要重新安装应用程序范围的提供程序。
您有一个错误-将您的功能BrowserModule
替换为CommonModule
。
https://stackoverflow.com/questions/71219443
复制相似问题