'Ng add @nrwl/workspace throws Cannot read property 'paths' of undefined
I just make a project with the angular cli and then run the command "ng add @nrwl/workspace" to change it to a nrwl workspace. But I am getting the following error "Cannot read property 'paths' of undefined".
I searched a bit in the internet and found out that someone had a similar error but his was that in angular.json test was missing I have everything needed in my angular.json.
Can someone maybe look at my json file and say what could possibly cause this error. I am using th e latest version of both nrwl and 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"
}
Solution 1:[1]
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": {
}
}
}
Solution 2:[2]
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": {
....
},
....
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maple512 |
Solution 2 | nhy |