Angular 非法状态:无法加载指令NgClass的摘要
在我的模块上运行Angular 非法状态:无法加载指令NgClass的摘要,angular,angular-compiler,Angular,Angular Compiler,在我的模块上运行ngc时,使用angular 4.4.3(和compiler 4.4.3),它可以正常工作。现在我升级到5.0.0(angular和编译器),出现以下错误: 错误:非法状态:无法加载[…]/node_modules/@angular/common/common.d.ts中指令NgClass的摘要 我的tsconfig.json文件如下所示: { "compilerOptions": { "baseUrl": ".", "declaration": true,
ngc
时,使用angular 4.4.3(和compiler 4.4.3),它可以正常工作。现在我升级到5.0.0(angular和编译器),出现以下错误:
错误:非法状态:无法加载[…]/node_modules/@angular/common/common.d.ts中指令NgClass的摘要
我的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"
]
}
我不知道是什么原因导致了我试图编译的文件出现问题。我在这里和那里看到过类似的错误,但与公共模块没有直接关系。由于错误不会发生在其他模块上,因此很难发布示例来重现错误
编辑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
]
}
}
}
如果我在MyModuleB
中包含CommonModule
,我还有一个错误:
Error: Illegal state: Could not load the summary for directive ActionSheetCmp in [...]/node_modules/ionic-angular/components/action-sheet/action-sheet-component.d.ts
现在我可以在
MyModuleB
中包含IonicModule
以产生下一个非法状态错误
(这次链接到翻译模块),但我在MyModuleB
中根本没有使用这些模块,所以为什么我需要全部导入它们?所以我不确定这背后的原因是什么,这很烦人,但似乎每个导入的模块都需要由子模块导入或从父模块导出。因此,在我的示例中,解决方案是:
@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
]
}
}
}
如果有人知道原因,请随时告诉我:)请发布你的
包.json
好吗?我编辑了这个问题,添加了一些代码,并对这个问题进行了更多思考。我认为angular5
可能改变了我们需要导入/导出模块的方式?您是否尝试过不在其中任何模块中导入IonicModule,而仅在根模块上导入它,使用forRoot并用于子页面IonicPageModule?我在他们的文档中看到,IonicModule只在root上导入module@Nicu它不会改变任何东西,基本上我在MyModuleA
中导入的任何模块都会在MyModuleB
中给我这个非法状态异常,因此CommonModule
也会和TranslateModule
一样