問題描述
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": {
}
}
}