当我尝试在angular cli中创建一个组件时,它显示了这个错误。我怎样才能摆脱它呢?

错误:多个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。

我使用的是angular cli版本:1.4.1


当前回答

当有多个模块时,需要指定模块名

 ng g c componentName --module=modulename.module 

其他回答

对我来说,这个命令工作:

ng g c new-component --module app

试试ng g component header——module app 这是我的工作

我的项目是使用Visual Studio Community 2017创建的,它创建了3个独立的模块:app.browser。Module, app.server.module和app.shared.module

为了创建我的组件,我检查了上面的答案,发现我的模块是app.share .module。

所以,我跑:

ng g c componentName --module=app.shared.module

Angular CLI: 6.0.8 节点:10.4.0 操作系统:linux x64 角:6.0.4

如果有一个特性模块(例如manager.module.ts)在。"/manager"子文件夹),而路由模块被外部化到单独的NgModule中(例如manager-routing.module.ts),错误消息如下:

超过一个模块匹配。使用skip-import选项可以跳过将组件导入到最近的模块。

不会出现,并且组件已正确生成并添加到manager.module.ts模块。

但是要注意命名惯例!路由模块的名称必须以“-routing”结束!

如果给路由模块一个这样的名字,例如manager-router.module。ts时,CLI会报错,并希望你提供——module选项来自动添加组件导入:

ng generate component some-name --module=manager.module.ts

or

ng generate component some-name --skip-import

如果您希望手动添加组件的导入

我有这个警告时,有这个角。json配置:

"prefix": "app_ng"

当更改为“app”时,一切都工作得很好。