我正在使用延迟加载的模块更改angular-4应用程序的结构,并在运行时遇到错误
ng build
错误:
错误:没有可用于依赖类型的模块工厂:ContextElementDependency
当我注释掉延迟加载的模块时,不会出现此错误。
这是我的 package.json :
{
"name": "picosmos",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"angular-in-memory-web-api": "~0.3.1",
"core-js": "^2.4.1",
"es6-promise": "3.0.2",
"lodash": "4.17.4",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"papaparse": "4.3.3",
"rxjs": "^5.4.2",
"systemjs": "0.19.39",
"webpack": "^3.6.0",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.4.2",
"@angular/compiler-cli": "4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.1.1",
"gulp": "3.9.1",
"gulp-less": "3.3.2",
"gulp-typescript": "3.2.0",
"http-server": "^0.9.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"less": "2.7.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.3.2",
"typescript": "~2.3.3"
}
}
全球安装(其中包括):
我在GitHub上发现了一些问题,但没有解决方案对我有所帮助。我尝试重新安装webpack
和@angular/cli
。什么都没有帮助。
有关此的任何建议/经验/提示吗?
这是我的AppModule
const appRoutes: Routes = [
// These routes cause the compile-error (ng build)
{ path: "Finances", loadChildren: "./Finances/finances.module#FinancesModule" },
{ path: "Test", loadChildren: "./Test/test.module#TestModule" },
{ path: "Media", loadChildren: "./Media/media.module#MediaModule" },
//These routes work
{ path: "Dashboard", component: DashboardComponent },
{ path: "Error/:errorId", component: ErrorComponent },
{ path: "", pathMatch: "full", redirectTo: "Dashboard"},
{ path: "**", redirectTo: "/Error/http404" }
];
e.g。 test.module.ts
:
// imports
const testRoutes: Routes = [
{
path: "",
component: IndexComponent,
},
];
@NgModule({
imports: [
RouterModule.forChild(
testRoutes
),
HttpModule,
CommonModule,
FormsModule,
SharedModule
],
declarations: [
IndexComponent
],
bootstrap: [
IndexComponent
]
})
export class TestModule {
}
答案 0 :(得分:1)
您应该使用相同版本的角度依赖项。所以改变:
"@angular/compiler-cli": "4.2.4"
到
"@angular/compiler-cli": "^4.2.4"