NX Affected returns TypeError: Cannot read properties of undefined (reading 'name')
See original GitHub issueCurrent Behavior
Running nx affected on my project returns the error: “TypeError: Cannot read properties of undefined (reading ‘name’)”
Expected Behavior
nx affected should work as expected
Steps to Reproduce
You can try reproduce the issue, that can be seen here, cloning my repository using the dev branch. If you try to run pnpm exec nx affected --target=build it returns the error.
Failure Logs
% pnpm exec nx affected --target=build
NX Affected criteria defaulted to --base=main --head=HEAD
nx.js affected
Run target for affected projects
Run command using --base=[SHA1] (affected by the committed, uncommitted and untracked changes): –base Base of the current branch (usually main) [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes): –base Base of the current branch (usually main) [string] –head Latest commit of the current branch (usually HEAD) [string]
or using: –files Change the way Nx is calculating the affected command by providing directly changed files, list of files delimited by commas [array] –uncommitted Uncommitted changes [boolean] –untracked Untracked changes [boolean]
Options: –help Show help [boolean] –version Show version number [boolean] –target Task to run for affected projects [string] [required] –parallel Max number of parallel processes [default is 3] [string] –output-style Defines how Nx emits outputs tasks logs [string] [choices: “dynamic”, “static”, “stream”, “stream-without-prefixes”] –all All projects [boolean] –exclude Exclude certain projects from being processed [array] [default: []] –runner This is the name of the tasks runner configured in nx.json [string] –skip-nx-cache Rerun the tasks even when the results are available in the cache [boolean] [default: false] –configuration This is the configuration to use when performing tasks on projects [string] –verbose Prints additional information about the commands (e.g., stack traces) [boolean] [default: false] –nx-bail Stop command execution after the first failed task [boolean] [default: false] –nx-ignore-cycles Ignore cycles in the task graph [boolean] [default: false]
Examples: affected --target=custom-target Run custom target for all affected projects affected --target=test --parallel=5 Run tests in parallel affected --target=test --all Run the test target for all projects affected --target=test --files=libs/mylib/src/index.ts Run tests for all the projects affected by changing the index.ts file affected --target=test --base=main --head=HEAD Run tests for all the projects affected by the changes between main and HEAD (e.g., PR) affected --target=test --base=main~1 --head=main Run tests for all the projects affected by the last commit on main
Find more information and examples at https://nx.dev/nx/affected
TypeError: Cannot read properties of undefined (reading ‘name’) at getTouchedNpmPackages (/Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/nx@15.0.1/node_modules/nx/src/project-graph/affected/locators/npm-packages.js:24:41) at /Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/nx@15.0.1/node_modules/nx/src/project-graph/affected/affected-project-graph.js:31:27 at Array.reduce (<anonymous>) at filterAffected (/Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/nx@15.0.1/node_modules/nx/src/project-graph/affected/affected-project-graph.js:30:52) at projectsToRun (/Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/nx@15.0.1/node_modules/nx/src/command-line/affected.js:101:55) at Object.<anonymous> (/Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/nx@15.0.1/node_modules/nx/src/command-line/affected.js:29:26) at Generator.next (<anonymous>) at fulfilled (/Users/matteo/Projects/GitHub/tsparticles/tsparticles/node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js:115:62) at processTicksAndRejections (node:internal/process/task_queues:96:5)
Environment
Both GitHub Actions and my MacBook with macOS Ventura (13.0) using latest pnpm version (7.14.0) and Node.JS 16 (16.17.1)
Issue Analytics
- State:
- Created a year ago
- Comments:5

Top Related StackOverflow Question
I believe that this is still an issue as of
15.2.1. We encountered this issue when migrating a package from outside our repo to inside our repo. The package in question was no longer inexternalNodeshere, but inside our workspace, as suchnpmPackagewasundefinedwhen it tried to find it.Thank you for providing the branch. I was able to reproduce it.
Something fixed this in
15.0.2. If I updaterepro-nx-affectedto15.0.2, things work as expected. 👍