You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Nx单体仓库中创建Angular库失败的问题求助

Nx单体仓库创建Angular库失败问题排查与解决

我有一个包含Angular应用的Nx单体仓库,尝试执行命令创建用于DDD架构的Angular库:

npx nx g @nrwl/angular:lib infrastructure --verbose

但执行失败,报错信息如下:

[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic
Project extension with invalid name (files) found.
Project extension with invalid name (files) found.
[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic
Project extension with invalid name (files) found.
Project extension with invalid name (files) found.
[NX] Angular devkit called `writeWorkspace`, this may have had unintended consequences in workspace.json
[NX] Double check workspace.json before proceeding
[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic
Project extension with invalid name (files) found.
Project extension with invalid name (files) found.
SchematicsException [Error]: Project "infrastructure" does not exist.
    at C:\Users\angel\Documents\Develop\Projects\MUNDO\Web App\evemundo-web-app\node_modules\@schematics\angular\component\index.js:99:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

 >  NX   Project "infrastructure" does not exist.


Error: Project "infrastructure" does not exist.
    at C:\Users\angel\Documents\Develop\Projects\MUNDO\Web App\evemundo-web-app\node_modules\@schematics\angular\component\index.js:99:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

执行普通库创建命令可以成功,但这不是我需要的Angular库:

npx nx g @nrwl/workspace:lib domain

依赖版本

"@angular/animations": "~14.2.0",
"@angular/cdk": "^14.2.0",
"@angular/common": "~14.2.0",
"@angular/compiler": "~14.2.0",
"@angular/core": "~14.2.0",
"@angular/forms": "~14.2.0",
"@angular/platform-browser": "~14.2.0",
"@angular/platform-browser-dynamic": "~14.2.0",
"@angular/router": "~14.2.0",
"devextreme": "^22.1.4",
"devextreme-angular": "^22.1.4",
"@angular-devkit/build-angular": "~14.2.0",
"@angular-eslint/eslint-plugin": "~14.0.0",
"@angular-eslint/eslint-plugin-template": "~14.0.0",
"@angular-eslint/template-parser": "~14.0.0",
"@angular/cli": "~14.2.0",
"@angular/compiler-cli": "~14.2.0",
"@angular/language-service": "~14.2.0",
"@nrwl/angular": "14.6.5",
"@nrwl/cli": "14.6.5",
"@nrwl/cypress": "14.6.5",
"@nrwl/eslint-plugin-nx": "14.6.5",
"@nrwl/jest": "14.6.5",
"@nrwl/linter": "14.6.5",
"@nrwl/nx-cloud": "14.6.2",
"@nrwl/workspace": "14.6.5",
"@types/jest": "28.1.1",
"@types/node": "16.11.7",

环境信息

  • NodeJS 16
  • Windows 10

解决步骤

  1. 修复workspace.json中的无效扩展
    报错中反复出现Project extension with invalid name (files) found,说明workspace.json内某个项目的配置存在非法的files扩展字段。打开该文件,检查所有项目的extensions节点,删除名为files的配置项。

  2. 清理缓存并重试
    执行命令清理Nx缓存:

npx nx reset

之后重新运行Angular库生成命令:

npx nx g @nrwl/angular:lib infrastructure --verbose
  1. 明确指定库类型
    若问题仍存在,尝试明确指定库的类型(如数据访问库、特性库等),示例命令:
npx nx g @nrwl/angular:lib infrastructure --type=data-access --verbose
  1. 更新Nx至同版本最新补丁
    虽然Angular 14.2与Nx 14.6.5理论上兼容,但可尝试更新Nx至同大版本的最新补丁版本:
npx nx migrate latest --from=14.6.5

执行完迁移命令后,运行:

npx nx migrate --run-migrations

内容的提问来源于stack exchange,提问作者alambertt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 14:31:02