在 .NET Core 项目中生成 Angular 2 组件时出现的预期错误(版本 0.8.3)
在 .NET Core 项目中生成新的 Angular 2 组件时,可能会遇到以下错误(从版本 0.8.3 开始):
Error locating module for declaration
SilentError: No module files found
要么
No app module found. Please add your new Class to your component.
Identical ClientApp/app/app.module.ts
[解]
-
将 app.module.client.ts 重命名为 app.client.module.ts
-
打开 app.client.module.ts:在声明前加上 3 个点“…”并将声明括在括号中。
例如:
[...sharedConfig.declarations, <MyComponent>]
-
打开 boot-client.ts:更新导入以使用新的 app.client.module 引用。
例如:
import { AppModule } from './app/app.client.module';
-
现在尝试生成新组件:
ng g component my-component
[说明]
Angular CLI 在项目中查找名为 app.module.ts 的文件,并尝试查找声明属性的引用以导入组件。这应该是一个数组(作为 sharedConfig.declarations 是),但是不会应用更改
[SOURCES]
- https://github.com/angular/angular-cli/issues/2962
- https://www.udemy.com/aspnet-core-angular/learn/v4/t/lecture/6848548 (第 3.33 节讲座撰稿人 Bryan Garzon)