nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.57k stars 2.36k forks source link

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

Closed matteobruni closed 2 years ago

matteobruni commented 2 years ago

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 () 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. (/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 () 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)

FrozenPandaz commented 2 years ago

I tried to reproduce this on the dev branch but wasn't able to.. is there another branch?

matteobruni commented 2 years ago

I tried to reproduce this on the dev branch but wasn't able to.. is there another branch?

I've made some changes to the project. I've moved some packages out from the repo. You can test the repro-nx-affected branch. It's relative to the failed GitHub action linked in my previous post

FrozenPandaz commented 2 years ago

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. :+1:

wittjosiah commented 1 year ago

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.

wittjosiah commented 1 year ago

After upgrading to 15.3.3 the issue seems to have been resolved again.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.