【问题标题】:Angular CLI create component throw error; Could not find an NgModuleAngular CLI 创建组件抛出错误;找不到 NgModule
【发布时间】:2019-06-19 07:21:36
【问题描述】:

我正在开发 Angular 6 应用程序并尝试使用 CLI 使用“ng g c myComponent”创建新组件,但出现错误

我的所有组件都在 app/(根级组件)的模块文件夹下

错误

Could not find an NgModule. Use the skip-import option to skip importing in NgModule.

警告信息

 Your global Angular CLI version (7.2.2) is greater than your local
 version (6.2.9). The local Angular CLI version is used.

 To disable this warning use "ng config -g cli.warnings.versionMismatch 
 false".
 Two or more projects are using identical roots. Unable to determine 
 project using current working directory. Using default workspace project 
 instead.

当我运行 ng --version 时,我得到以下应用版本

Angular CLI: 6.2.9
Node: 8.9.3
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.8.9
@angular/cli                      6.2.9
@ngtools/webpack                  6.0.8
@schematics/angular               0.8.9
@schematics/update                0.8.9
rxjs                              5.5.12
typescript                        2.5.3
webpack                           4.8.3

【问题讨论】:

  • 我想您可能只是在错误的路径中运行此命令。您完全确定您是在组件所在的文件夹中运行此命令吗?
  • 我参考了这个博客,但我没有找到任何解决方案
  • 我相信我在正确的文件夹 C:\Developments\Dev\MyAngularProject\src\app\modules> ng g c MyComponent
  • Gonzalo Lorieto,我没有找到解决方案...

标签: node.js angular6


【解决方案1】:

确保您的应用模块位于生成组件的文件夹中。这为我解决了。

【讨论】:

    【解决方案2】:

    我在特定功能(或项目)中创建组件时遇到了同样的问题。我意识到我必须进入 app 目录。

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多