question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NX Affected returns TypeError: Cannot read properties of undefined (reading 'name')

See original GitHub issue

Current 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:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
wittjosiahcommented, Dec 1, 2022

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 in externalNodes here, but inside our workspace, as such npmPackage was undefined when it tried to find it.

1reaction
FrozenPandazcommented, Oct 27, 2022

Thank you for providing the branch. I was able to reproduce it.

Something fixed this in 15.0.2. If I update repro-nx-affected to 15.0.2, things work as expected. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'endsWith')\n ...
After updating to nx : 13.8.5. Running nx format:check throws error-. { stack: "TypeError: Cannot read properties of undefined (reading ...
Read more >
NX Cannot read properties of undefined (reading 'endsWith')
NX Failed to run update-ngcc-postinstall from @nrwl/angular. This workspace is NOT up to date! NX rule is not a function. So I set...
Read more >
cannot read properties of undefined (reading 'auth') - You.com
To fix the “cannot read property of undefined” error, check that the value is not undefined before accessing the property. For example, in...
Read more >
Pulse · nrwl/nx · GitHub
Error when running affected: Cannot read properties of undefined (reading 'name'). #13802 closed Dec 15, 2022. Missing --project flag in React storybook ...
Read more >
Using Nx Workspace generators to scaffold new blog posts
npx nx generate @nrwl/react:component --name=Youtube --project=shared-mdx-elements --no-interactive. As you can see, Nx generators not only scaffold files ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found