Angular 7 CLI ng 生成组件错误:“无法读取未定义的属性‘sourceRoot’”

问题描述 投票:0回答:2

当我尝试在 CLI 上运行以下命令时收到以下错误:

ng generate component [component-name]

我不断得到:

Cannot read property 'sourceRoot' of undefined

我猜我是在更新了我所在的 Angular 版本后开始获取它的。 Cannot read property 'sourceRoot' of undefined

解决方案见回复。

angular components command-line-interface angular7 generate
2个回答
0
投票

要解决这个问题,我必须转到我的 Angular.json 文件夹。

  1. 搜索“e2e”
  2. 将“root”从“e2e/”更新为“/”。 该位置位于“[项目名称]-e2e”下

enter image description here

更新后我就可以运行命令

ng generate component [component-name]

没有出现任何问题

ng generate component product-search


0
投票

出现此问题是因为 Angular cli 找不到当前项目|文件夹。 要解决这个问题,只需在项目文件夹(对于多项目)应用程序或 src 应用程序下的指定文件夹中运行 ng,例如 cd src/app,然后运行 ng g c 产品搜索或将 angular.json 中的 sourceRoot 更改为 Roger Perez 的答案

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.