我已经查看了所有关于此的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
答案 0 :(得分:0)
有时ng无法检测到某些原因。
您可以再次运行命令
dict(enumerate(listoflists, 1))
如果您通过ng serve
命令运行
npm