将 'ng generate component' 用于 Angular 时出错 4
Error When using 'ng generate component' for Angular 4
我有一个 Angular 4
项目,起初我可以使用 ng generate component
命令,但自从我实施了 Routing
该命令不再有效,因为我收到以下错误
Error: More than one module matches. Use skip-import option to skip importing the component into the closest module.
More than one module matches. Use skip-import option to skip importing the component into the closest module.
我不太确定是不是 Routing
造成的,但这似乎是我唯一能想到的,我需要修复它
尝试 运行 ng g component ComponentName
模块文件夹内。
错误不言自明,因为您的项目中至少有两个模块。您需要使用 skip-import 标志,因为 Angular 无法决定应该导入哪个模块。添加跳过导入标志后,错误将消失。但是您必须手动将组件导入到您希望使用它的模块中。
像这样:
ng generate component newComponent --skip-import
我在 Windows 10 上使用 VS 2017 和 @angular/cli (6.0.8):
ng g c components/name-component ---模块../app/app.shared.module.ts
并且运行这个命令来自...\ClientApp\app
我有一个 Angular 4
项目,起初我可以使用 ng generate component
命令,但自从我实施了 Routing
该命令不再有效,因为我收到以下错误
Error: More than one module matches. Use skip-import option to skip importing the component into the closest module. More than one module matches. Use skip-import option to skip importing the component into the closest module.
我不太确定是不是 Routing
造成的,但这似乎是我唯一能想到的,我需要修复它
尝试 运行 ng g component ComponentName
模块文件夹内。
错误不言自明,因为您的项目中至少有两个模块。您需要使用 skip-import 标志,因为 Angular 无法决定应该导入哪个模块。添加跳过导入标志后,错误将消失。但是您必须手动将组件导入到您希望使用它的模块中。
像这样:
ng generate component newComponent --skip-import
我在 Windows 10 上使用 VS 2017 和 @angular/cli (6.0.8):
ng g c components/name-component ---模块../app/app.shared.module.ts
并且运行这个命令来自...\ClientApp\app