Gui*_*ume 5 angular angular-compiler
ngc在我的模块上运行时,它过去经常使用angular 4.4.3(和编译器4.4.3)可以正常工作。现在,我升级到5.0.0(包括angular和编译器),并且出现以下错误:
错误:非法状态:无法将指令NgClass的摘要加载到[...] / node_modules/@angular/common/common.d.ts中。
我的tsconfig.json文件如下所示:
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"stripInternal": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "[...]/",
"paths": {...},
"rootDir": "[...]/plugins/",
"target": "es5",
"skipLibCheck": true,
"lib": [
"es2015",
"dom"
],
"sourceMap": true,
"inlineSources": true,
"noImplicitAny": true
},
"files": [
"[...]/plugins/users/index.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我不知道是什么原因导致我尝试编译的文件出现问题。我到处都看到了类似的错误,但与普通模块没有直接关系。发布示例以重现错误是很困难的,因为其他模块上不会发生
编辑1:
我的设置如下:一个模块MyModuleA成功构建,MyModuleB使用MyModuleA该模块则不构建。
@NgModule({
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild()
]
})
export class MyModuleA {
static forRoot(): ModuleWithProviders {
return {
ngModule: MyModuleA,
providers: [
ModuleAService
]
};
}
}
@NgModule({
imports: [
HttpClientModule,
MyModuleA
]
})
export class MyModuleB {
/**
* Instantiate module (for main module only).
*/
static forRoot(): ModuleWithProviders {
return {
ngModule: MyModuleB,
providers: [
ModuleBService
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果包括我CommonModule在MyModuleB,我有另外一个错误:
Error: Illegal state: Could not load the summary for directive ActionSheetCmp in [...]/node_modules/ionic-angular/components/action-sheet/action-sheet-component.d.ts
Run Code Online (Sandbox Code Playgroud)
现在我可以包括IonicModule在MyModuleB有下一次illegal state error(此时挂翻译模块),但我不是在所有使用这些模块MyModuleB那么为什么我需要导入它们呢?
So I'm not sure what is the reason behind this, it's quite annoying, but it appears every imported module needs to be either imported by a sub-module or exported from the parent module. So in my example the solution would be to do:
@NgModule({
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild()
],
exports: [
CommonModule,
IonicModule,
TranslateModule
]
})
export class MyModuleA {
static forRoot(): ModuleWithProviders {
return {
ngModule: MyModuleA,
providers: [
ModuleAService
]
};
}
}
@NgModule({
imports: [
HttpClientModule,
MyModuleA
]
})
export class MyModuleB {
/**
* Instantiate module (for main module only).
*/
static forRoot(): ModuleWithProviders {
return {
ngModule: MyModuleB,
providers: [
ModuleBService
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
If anyone knows why, feel free to enlighten me :)
| 归档时间: |
|
| 查看次数: |
747 次 |
| 最近记录: |