![](/img/trans.png)
[英]Providing Angular "ErrorHandler" in AppModule cause "Cannot find module" in lazy child module routing
[英]cannot find module lazy preload Angular Routing
我已經看過所有關於此的SO問題,但仍然無法解決。
我正在預加載模塊,但出現錯誤:
錯誤錯誤:未捕獲(承諾):錯誤:找不到模塊'./results.results.module'錯誤:找不到模塊'./results.results.module'在:4200 / main.js:48:11 [角度]
我已經對拼寫進行了三重檢查,甚至制作了一個小應用程序嘗試重新創建它,但是它運行良好,我不確定自己做錯了什么。 不幸的是,我不能發布一個真實的機密示例。
AppRoutingModule
import { NgModule } from '@angular/core';
import { PlanComponent } from 'app/plan/plan.component';
import { MaintenanceComponent } from './maintenance/maintenance/maintenance.component';
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
const appRoutes: Routes = [
{ path: '', redirectTo: '/plan', pathMatch: 'full' },
{ path: 'plan', component: PlanComponent },
{ path: 'maintenance', component: MaintenanceComponent },
// this is the failing module
{ path: 'results', loadChildren: './results/results.module#ResultsModule' },
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, {
preloadingStrategy: PreloadAllModules
})
],
exports: [RouterModule]
})
export class AppRoutingModule {}
的AppModule
import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from 'app/app-routing.module';
... other components not including the lazy loaded module
...
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpModule,
BrowserAnimationsModule,
SharedModule.forRoot(),
MaintenanceModule
]
...
預載路由模塊
import { NgModule } from '@angular/core';
... component imports
import { Routes, RouterModule } from '@angular/router';
const resultsRoutes: Routes = [
{
path: '', component: ResultsComponent, children: [
{ path: 'featurechild', component: featureChildComponent }
]
},
];
@NgModule({
imports: [
RouterModule.forChild(resultsRoutes)
],
exports: [RouterModule]
})
export class ResultsRoutingModule {}
預裝模塊
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
... other component imports
import { ResultsRoutingModule } from './results-routing.module';
...
imports: [
CommonModule,
ResultsRoutingModule,
FormsModule,
SharedModule,
...
export class ResultsModule {}
的package.json
{
"name": "gui",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve --deploy-url=/huskies",
"build": "ng build --dev --deploy-url=/huskies",
"prod": "ng build --prod --deploy-url=/huskies",
"test": "ng test",
"lint": "ng lint",
"pree2e": "webdriver-manager update --standalone false --gecko false --ignore_ssl",
"e2e": "ng e2e -uw fal"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.0.2",
"@angular/common": "^7.0.3",
"@angular/compiler": "^7.0.3",
"@angular/core": "^7.0.3",
"@angular/forms": "^7.0.3",
"@angular/http": "^7.0.3",
"@angular/platform-browser": "^7.0.3",
"@angular/platform-browser-dynamic": "^7.0.3",
"@angular/platform-server": "^7.0.3",
"@angular/router": "^7.0.3",
"cesium": "^1.43.0",
"core-js": "^2.5.7",
"enhanced-resolve": "^3.4.1",
"ng-event-source": "^1.0.14",
"rxjs": "^6.3.3",
"three": "^0.87.1",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.5",
"@angular/cli": "^7.0.4",
"@angular/compiler-cli": "^7.0.2",
"@angular/language-service": "^7.0.2",
"@types/jasmine": "^2.8.9",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^10.12.2",
"codelyzer": "^4.5.0",
"jasmine-core": "^3.3.0",
"jasmine-spec-reporter": "^4.2.1",
"karma": "^3.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "^1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "^5.4.1",
"rxjs-tslint": "^0.1.5",
"ts-node": "~3.3.0",
"tslint": "^5.11.0",
"typescript": "^3.1.6"
}
}
文件夾結構(所有內容都在根應用目錄中):
results/results.module.ts
results/results-routing.module.ts
app.module.ts
app-routing.module.ts
有時ng無法檢測到某些原因。
您可以再次運行命令嗎
ng serve
如果通過npm
命令運行,則
npm start
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.