Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined (Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined)


問題描述

Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined (Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined)

我只是用 angular cli 創建一個項目,然後運行命令“ng add @nrwl/workspace”。將其更改為 nrwl 工作區。但是我收到以下錯誤“無法讀取未定義的屬性“路徑””。

我在互聯網上搜索了一下,發現有人有類似的錯誤,但他的錯誤是在 angular.json缺少測試我的 angular.json 中有所需的一切。

有人可以查看我的 json 文件並說出可能導致此錯誤的原因。我正在使用最新版本的 nrwl 和 angular

Angula.json

   {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "moniesta‑admin": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular‑devkit/build‑angular:browser",
          "options": {
            "outputPath": "dist/moniesta‑admin",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular‑devkit/build‑angular:dev‑server",
          "options": {
            "browserTarget": "moniesta‑admin:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "moniesta‑admin:build:production"
            }
          }
        },
        "extract‑i18n": {
          "builder": "@angular‑devkit/build‑angular:extract‑i18n",
          "options": {
            "browserTarget": "moniesta‑admin:build"
          }
        },
        "test": {
          "builder": "@angular‑devkit/build‑angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular‑devkit/build‑angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular‑devkit/build‑angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "moniesta‑admin:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "moniesta‑admin:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "moniesta‑admin"
}


參考解法

方法 1:

I know it's late to answer this question but I hope this could be help.

I have experienced the same issue while trying to serve backend using both nestjs and express using Nx generate CLI (nx g @nrwl/express:app my‑app and nx g @nrwl/nest:app my‑nest‑app. Right after run nx server my‑app, terminal print below error

{
  stack: "TypeError: Cannot read property 'endsWith' of undefined\n" +
    '    at createProjectRootMappings (/Users/path‑to‑root/node_modules/nx/src/project‑graph/file‑map‑utils.js:12:38)\n' +
    '    at createProjectFileMap (/Users/path‑to‑root/node_modules/nx/src/project‑graph/file‑map‑utils.js:27:33)\n' +
    '    at /Users/path‑to‑root/node_modules/nx/src/daemon/server/project‑graph‑incremental‑recomputation.js:92:85\n' +
    '    at Generator.next (<anonymous>)\n' +
    '    at fulfilled (/Users/path‑to‑root/node_modules/tslib/tslib.js:115:62)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:95:5)',
  message: "Cannot read property 'endsWith' of undefined\n" +
    '\n' +
    'Because of the error the Nx daemon process has exited. The next Nx command is going to restart the daemon process.\n' +
    'If the error persists, please run "nx reset".'
}

Turn out there's missing line in file project.json generate by nx

{
  "root": "packages/my‑app", // add this line
  "sourceRoot": "packages/my‑app/src",
  "projectType": "application",
  "targets": {
    ....
  },
  ....
}

方法 2:

I also encountered this kind of problem, I solved it like this: in the root directory tsconfig.json A paths parameter is required in. like this:

{
  "compilerOptions": {
    "paths": {
    }
  }
}

(by HasonhyMaple512)

參考文件

  1. Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined (CC BY‑SA 2.5/3.0/4.0)

#monorepo #nrwl #Angular #web-applications






相關問題

Webpack 無法解決 node_modules 惰性資產 (Webpack Cannot Resolve node_modules lazy assets)

如何使用 gradle 和多個 gradle 項目實現 monorepo (how to implement monorepo with gradle and multiple gradle projects)

Monorepos 和跨包開發。使用 src/ 或 dist/? (Monorepos and cross package development. To use src/ or dist/?)

如何在 Monorepo 中運行多個開發包 (How to run multiple packages in development inside a Monorepo)

帶有許多 npm 腳本的 Monorepo (Monorepo with Many npm-scripts)

Pip 從 github monorepo 中安裝 python 庫 (Pip install a python library from within a github monorepo)

你能撤消 lerna 引導程序嗎? (Can you undo a lerna bootstrap?)

pnpm -- 同步依賴版本 (pnpm -- sync versions of dependencies)

如何在同一個 monorepo 中的 Python 項目之間共享開發依賴項? (how to share dev-dependencies between Python projects within the same monorepo?)

Monorepo – Yarn 工作區 Typescript Node.JS 項目 – 運行 nodemon 時找不到模塊 (Monorepo – Yarn workspaces Typescript Node.JS project – cannot find module when running nodemon)

在 Azure Devops 的 mono repo 中設置項目的工作目錄 (Set working directory of a project in mono repo in Azure Devops)

紗線工作區共享包未在 create-react-app 中加載 (yarn workspaces shared package does not load in create-react-app)







留言討論