nx: "TypeError: Cannot read properties of undefined (reading 'endsWith')\n"

Current Behavior

After updating to nx : 13.8.5 Running nx format:check throws error-

{
  stack: "TypeError: Cannot read properties of undefined (reading 'endsWith')\n" +
    '    at createProjectRootMappings (D:\\Inboxwidgets\\desk-ng\\node_modules\\@nrwl\\workspace\\src\\core\\file-map-utils.js:12:38)\n' +
    '    at createProjectFileMap (D:\\Inboxwidgets\\desk-ng\\node_modules\\@nrwl\\workspace\\src\\core\\file-map-utils.js:27:33)\n' +
    '    at D:\\Inboxwidgets\\desk-ng\\node_modules\\@nrwl\\workspace\\src\\core\\project-graph\\daemon\\server\\project-graph-incremental-recomputation.js:92:85\n' +
    '    at Generator.next (<anonymous>)\n' +
    '    at fulfilled (D:\\Inboxwidgets\\desk-ng\\node_modules\\tslib\\tslib.js:114:62)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:96:5)',
  message: "Cannot read properties of undefined (reading 'endsWith')\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".'
}

Expected Behavior

Steps to Reproduce

run nx format:check OR run nx run-many --all --target=lint

Migration.json

{
  "migrations": [
    {
      "version": "13.0.0-beta.1",
      "description": "Add default base to nx.json if its not currently set",
      "factory": "./src/migrations/update-13-0-0/set-default-base-if-not-set",
      "cli": "nx",
      "package": "@nrwl/workspace",
      "name": "set-default-base-if-not-set"
    },
    {
      "version": "13.0.0-beta.4",
      "description": "Move global settings into nx.json, and project specific settings into workspace.json",
      "cli": "nx",
      "implementation": "./src/migrations/update-13-0-0/config-locations/config-locations",
      "package": "@nrwl/workspace",
      "name": "13-0-0-config-locations"
    },
    {
      "version": "13.2.0",
      "description": "Set --parallel=1 for existing repos to preserve the existing behavior",
      "cli": "nx",
      "implementation": "./src/migrations/update-13-2-0/set-parallel-default",
      "package": "@nrwl/workspace",
      "name": "set-parallel-default"
    },
    {
      "version": "13.3.0-beta.0",
      "description": "@nrwl/workspace:tsc is now @nrwl/js:tsc",
      "cli": "nx",
      "implementation": "./src/migrations/update-13-3-0/update-tsc-executor-location",
      "package": "@nrwl/workspace",
      "name": "13-3-0-tsc-location"
    },
    {
      "version": "13.6.0-beta.0",
      "description": "Remove old options that are no longer used",
      "cli": "nx",
      "implementation": "./src/migrations/update-13-6-0/remove-old-task-runner-options",
      "package": "@nrwl/workspace",
      "name": "13-6-0-remove-old-task-runner-options"
    },
    {
      "cli": "nx",
      "version": "13.0.0-beta.10",
      "description": "Adds postcss packages needed for Tailwind support if ng-packagr is already installed.",
      "factory": "./src/migrations/update-13-0-0/add-postcss-packages",
      "package": "@nrwl/angular",
      "name": "add-postcss-packages"
    },
    {
      "cli": "nx",
      "version": "13.2.0-beta.1",
      "description": "Remove deprecated options from webpack-server and webpack-browser.",
      "factory": "./src/migrations/update-13-2-0/update-angular-config",
      "package": "@nrwl/angular",
      "name": "update-angular-config"
    },
    {
      "cli": "nx",
      "version": "13.2.0-beta.1",
      "description": "Remove enableIvy and add compilationMode to library tsconfig and remove deprecated ng-packagr options.",
      "factory": "./src/migrations/update-13-2-0/update-libraries",
      "package": "@nrwl/angular",
      "name": "update-libraries"
    },
    {
      "cli": "nx",
      "version": "13.2.0-beta.1",
      "description": "Update jest config to support jest-preset-angular",
      "factory": "./src/migrations/update-13-2-0/update-angular-jest-config",
      "package": "@nrwl/angular",
      "name": "update-angular-jest-config"
    },
    {
      "cli": "nx",
      "version": "13.2.0-beta.1",
      "description": "Move some imports from @nrwl/angular/testing to jasmine-marbles",
      "factory": "./src/migrations/update-13-2-0/update-testing-imports",
      "package": "@nrwl/angular",
      "name": "update-testing-imports"
    },
    {
      "cli": "nx",
      "version": "13.2.0",
      "description": "In Angular version 13, the `teardown` flag in `TestBed` will be enabled by default. This migration automatically opts out existing apps from the new teardown behavior.",
      "factory": "./src/migrations/update-13-2-0/opt-out-testbed-teardown",
      "package": "@nrwl/angular",
      "name": "opt-out-testbed-teardown"
    },
    {
      "cli": "nx",
      "version": "13.3.0-beta.0",
      "description": "In Angular version 13, the ESM became a first class citizen. This means the webpack config generated must be modified to support modules.",
      "factory": "./src/migrations/update-13-3-0/update-mfe-webpack-config",
      "package": "@nrwl/angular",
      "name": "update-mfe-config-to-module-syntax"
    },
    {
      "cli": "nx",
      "version": "13.4.5-beta.7",
      "description": "Remove the default for the invalid 'style' option for the library generator if configured.",
      "factory": "./src/migrations/update-13-5-0/remove-library-generator-style-default",
      "package": "@nrwl/angular",
      "name": "remove-library-generator-style-default"
    },
    {
      "cli": "nx",
      "version": "13.5.0-beta.0",
      "description": "A lot of changes to how MFEs operate were discovered and merged without appropriate migrations. This should cover migrating existing MFEs to the latest, using ESM and optmized production bundles.",
      "factory": "./src/migrations/update-13-5-0/update-mfe-configs",
      "package": "@nrwl/angular",
      "name": "fix-incorrect-mfe-setups"
    },
    {
      "cli": "nx",
      "version": "13.8.1",
      "description": "Angular doesn't attach styles.js to index.html with type=module in dev mode, meaning an error is written to the console. Cypress falls over on this error. Add logic to Cypress e2e projects to ignore this error.",
      "factory": "./src/migrations/update-13-8-1/add-cypress-mfe-workaround",
      "package": "@nrwl/angular",
      "name": "add-cypress-mfe-workaround"
    },
    {
      "cli": "nx",
      "version": "13.8.4",
      "description": "Karma coverage is broken since Angular 13 upgarde and the karma config is severely out of date. Bring it up to date fixing the coverage issue.",
      "factory": "./src/migrations/update-13-8-4/migrate-karma-conf",
      "package": "@nrwl/angular",
      "name": "migrate-karma-config"
    },
    {
      "version": "13.0.0",
      "factory": "./update-13/schematic-options",
      "description": "Remove no longer valid Angular schematic options from `angular.json`.",
      "package": "@angular/cli",
      "name": "schematic-options-13"
    },
    {
      "version": "13.0.0",
      "factory": "./update-13/update-angular-config",
      "description": "Remove deprecated options from 'angular.json' that are no longer present in v13.",
      "package": "@angular/cli",
      "name": "update-angular-config-v13"
    },
    {
      "version": "13.0.0",
      "factory": "./update-13/update-libraries",
      "description": "Update library projects to be published in partial mode and removed deprecated options from ng-packagr configuration.",
      "package": "@angular/cli",
      "name": "update-libraries-v13"
    },
    {
      "version": "13.0.0",
      "factory": "./update-13/drop-ie-polyfills",
      "description": "Remove polyfills required only for Internet Explorer which is no longer supported.",
      "package": "@angular/cli",
      "name": "drop-ie-polyfills"
    },
    {
      "version": "13.0.0",
      "factory": "./update-13/update-gitignore",
      "description": "Updating '.gitignore' to include '.angular/cache'.",
      "package": "@angular/cli",
      "name": "update-gitignore"
    },
    {
      "version": "13.0.0-beta",
      "description": "Migrates `[routerLink]=\"\"` in templates to `[routerLink]=\"[]\"` because these links are likely intended to route to the current page with updated fragment/query params.",
      "factory": "./migrations/router-link-empty-expression/index",
      "package": "@angular/core",
      "name": "migration-v13-router-link-empty-expression"
    },
    {
      "version": "13.0.0-beta",
      "description": "In Angular version 13, the `teardown` flag in `TestBed` will be enabled by default. This migration automatically opts out existing apps from the new teardown behavior.",
      "factory": "./migrations/testbed-teardown/index",
      "package": "@angular/core",
      "name": "migration-v13-testbed-teardown"
    },
    {
      "version": "13.1.0-beta",
      "description": "As of Angular version 13, `entryComponents` are no longer necessary.",
      "factory": "./migrations/entry-components/index",
      "package": "@angular/core",
      "name": "migration-v13.1-entry-components"
    },
    {
      "version": "13.0.0-0",
      "description": "Updates Angular Material to v13",
      "factory": "./ng-update/index#updateToV13",
      "package": "@angular/material",
      "name": "migration-v13"
    },
    {
      "version": "13.0.0-0",
      "description": "Updates the Angular CDK to v13",
      "factory": "./ng-update/index#updateToV13",
      "package": "@angular/cdk",
      "name": "migration-v13"
    },
    {
      "version": "13.1.2-beta.0",
      "cli": "nx",
      "description": "Support .test. file names in tsconfigs",
      "factory": "./src/migrations/update-13-1-2/update-tsconfigs-for-tests",
      "package": "@nrwl/jest",
      "name": "update-ts-config-for-test-filenames"
    },
    {
      "version": "13.4.4-beta.0",
      "cli": "nx",
      "description": "Create a root babel config file if it doesn't exist and using babel-jest in jest.config.js and add @nrwl/web as needed",
      "factory": "./src/migrations/update-13-4-4/add-missing-root-babel-config",
      "package": "@nrwl/jest",
      "name": "add-missing-root-babel-config"
    },
    {
      "cli": "nx",
      "version": "13.3.0-beta.0",
      "description": "Update eslint-rules jest.config.js in order to support ESLint v8 exports mapping, remove category field",
      "factory": "./src/migrations/update-13-3-0/eslint-8-updates",
      "package": "@nrwl/linter",
      "name": "eslint-8-updates"
    }
  ]
}

nx report

Node : 16.13.1
   OS   : win32 x64
   yarn : 1.22.17
   nx : 12.9.0
   @nrwl/angular : 13.8.5
   @nrwl/cli : 12.9.0
   @nrwl/cypress : 13.8.5
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.5
   @nrwl/eslint-plugin-nx : 13.8.5
   @nrwl/express : undefined
   @nrwl/jest : 13.8.5
   @nrwl/js : undefined
   @nrwl/linter : 13.8.5
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : undefined
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.8.5
   @nrwl/tao : 12.9.0
   @nrwl/web : undefined
   @nrwl/workspace : 13.8.5
   typescript : 4.5.5
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:
         @angular/animations: 13.2.7
         @angular/cdk: 13.2.6
         @angular/common: 13.2.7
         @angular/compiler: 13.2.7
         @angular/core: 13.2.7
         @angular/forms: 13.2.7
         @angular/material: 13.2.6
         @angular/platform-browser: 13.2.7
         @angular/platform-browser-dynamic: 13.2.7
         @angular/router: 13.2.7
         @ngneat/transloco: 2.23.3
         @angular-devkit/build-angular: 13.2.6
         @angular/cli: 13.2.6
         @angular/compiler-cli: 13.2.7
         @angular/language-service: 13.2.7

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 36 (6 by maintainers)

Most upvoted comments

Literally just folowed the docs on creating a workspace and addding an application using @nrwl/nest and i encountered this error.

Don’t think this should be closed?

I’ve just started using nx 5 mintues ago and i’m blocked already lol

Edit

For anyone coming here from a search - turns out the nest package is missing a crucial line in the project.json

"sourceRoot": "apps/api/src",
  "projectType": "application",
  "root": "apps/api", // << add this

When I came across this issue it had to do with projects being in my nx.json. Removing the entire projects object from the nx.json solved this issue. The migrate command should ideally remove it for the user depending on the version number.

I can reproduce this error by simply running:

npx create-nx-workspace --preset=ts

And then in the workspace:

npm install --save-dev @nrwl/node

And then creating a node app and attempting to build it.

This is because none of the examples instruct the user to append @latest to their npx command. In my case, I had a cached version of create-nx-workspace that was v13 (see: https://github.com/npm/cli/issues/4108), but installing @nrwl/node installed v14.

This seems like a very common issue for new users to experience, I would recommend doing two things:

  1. Update the command in the getting started docs to be npx create-nx-workspace@latest
  2. Detect mismatched @nrwl package versions (either in a post install script or at runtime) and output a more user friendly error explaining the problem.

I have the same issue, newly generated workspace

  Node : 16.14.0
   OS   : darwin arm64
   npm  : 8.3.1
   
   nx : 13.10.4
   @nrwl/angular : Not Found
   @nrwl/cypress : 13.10.4
   @nrwl/detox : Not Found
   @nrwl/devkit : 13.10.4
   @nrwl/eslint-plugin-nx : 13.10.4
   @nrwl/express : 14.1.4
   @nrwl/jest : 13.10.4
   @nrwl/js : 13.10.4
   @nrwl/linter : 13.10.4
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.1.4
   @nrwl/nx-cloud : 14.0.3
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 13.10.4
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 13.10.4
   @nrwl/web : 13.10.4
   @nrwl/workspace : 13.10.4
   typescript : 4.6.4
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:

repro github repo https://github.com/vire/nx-reproduce-bug-6631

run npm i and nx build and you will see image

Thanks a lot for your comment @JoshuaCWebDeveloper !!!

I solved the error - “TypeError: Cannot read property ‘nodes’ of undefined” that occurs during application startup using clear bootstrap from official docs - https://nx.dev/packages/nest

I ran command - “nx migrate latest”

I also ran into this issue, even after running a migration. The issue ended up being that despite the migration, my project had been initialized with the wrong @nrwl/cli version:

image

I updated this to match the rest of the versions and everything worked.

@well-balanced all @nrwl packages versions should be the same. If you want the latest version of nrwl/node, you should migrate to the latest version of NX

In my case, I had installed a version of @nrwl/node newer than the version of the rest of @nrwl/ packages. Making sure that all the packages from @nrwl were in the same version solved to me.

Although I could replicate the issue by switching between Node v14 and v16 - the core issue is that an older nrwl/workspace<v14.0.6 is still being downloaded as a dependency (alongside v14.1.8). The old version is being called on post-install and then expecting the root property in the project configuration (angular.json/project.json) to be present. This was removed in 14.0.6 with the Remove root property from project.json files migration. Remove the lock file and check if there are any community plugins needing updating too. In my case it was @jscutlery/semver that needed updating.

Update:

I’ve updated nx to the latest version 14.1.4 using nx migrate and now it works 🥇