nrwl / nx

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

TypeError: Cannot read properties of undefined (reading 'name') when running nx affected #13668

Closed jericopingul closed 1 year ago

jericopingul commented 1 year ago

Current Behavior

Running into an error when running nx affected because the resulting undefined returned by an [].find() isn't handled.

image

Expected Behavior

No error, undefined is handled.

Github Repo

https://github.com/jericopingul/nx-affected-issue

Steps to Reproduce

  1. Clone the project linked
  2. Checkout this PR branch with git checkout test
  3. Run pnpm i and then pnpm nx affected --target=lint

Nx Report

pnpm nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin x64
   pnpm : 7.14.0

   nx : 15.3.0
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.3.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.3.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.3.0
   @nrwl/js : 15.3.0
   @nrwl/linter : 15.3.0
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : Not Found
   @nrwl/workspace : 15.3.0
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

TypeError: Cannot read properties of undefined (reading 'name')
    at getTouchedNpmPackages (/Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/nx@15.3.0/node_modules/nx/src/project-graph/affected/locators/npm-packages.js:24:41)
    at /Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/nx@15.3.0/node_modules/nx/src/project-graph/affected/affected-project-graph.js:31:27
    at Array.reduce (<anonymous>)
    at filterAffected (/Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/nx@15.3.0/node_modules/nx/src/project-graph/affected/affected-project-graph.js:30:52)
    at projectsToRun (/Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/nx@15.3.0/node_modules/nx/src/command-line/affected.js:100:55)
    at Object.<anonymous> (/Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/nx@15.3.0/node_modules/nx/src/command-line/affected.js:29:26)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/jericopingul/projects/nx-affected-issue/node_modules/.pnpm/tslib@2.4.1/node_modules/tslib/tslib.js:115:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {stack: 'TypeError: Cannot read properties of undefine…ions (node:internal/process/task_queues:96:5)', message: 'Cannot read properties of undefined (reading 'name')'}

Additional Information

No response

DoomAndLove commented 1 year ago

I've got the same error myself when looking to add a new lib with a package.json for publishing the lib

yarn nx report

 >  NX   Report complete - copy this into the issue template

   Node : 16.16.0
   OS   : win32 x64
   yarn : 3.3.0

   nx : 15.0.13
   @nrwl/angular : 15.0.13
   @nrwl/cypress : 15.0.13
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.0.13
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.0.13
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.0.13
   @nrwl/js : 15.0.13
   @nrwl/linter : 15.0.13
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 15.0.13
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 15.0.13
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.0.13
   @nrwl/web : Not Found
   @nrwl/webpack : 15.0.13
   @nrwl/workspace : 15.0.13
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         ng-zorro-antd: 14.2.1
         ngx-daterangepicker-material: 6.0.0
         @compodoc/compodoc: 1.1.19
         @jscutlery/semver: 2.27.1
         ngx-deploy-npm: 4.3.0
         nx-stylelint: 14.0.2
newmankyle commented 1 year ago

I have a similar issue to @DoomAndLove. If I log inside npm-packages.js and inspect what's failing I get this:

EDIT: after debugging I've got more info. This is what yarn.lock looks like

"html-tags@npm:^3.2.0":
  version: 3.2.0
  resolution: "html-tags@npm:3.2.0"
  checksum: <redacted>
  languageName: node
  linkType: hard

"html-webpack-plugin-4@npm:html-webpack-plugin@^4":
  version: 4.5.2
  resolution: "html-webpack-plugin@npm:4.5.2"
  dependencies:
    "@types/html-minifier-terser": ^5.0.0
    "@types/tapable": ^1.0.5
    "@types/webpack": ^4.41.8
    html-minifier-terser: ^5.0.1
    loader-utils: ^1.2.3
    lodash: ^4.17.20
    pretty-error: ^2.1.1
    tapable: ^1.1.3
    util.promisify: 1.0.0
  peerDependencies:
    webpack: ^4.0.0 || ^5.0.0
  checksum: <redacted>
  languageName: node
  linkType: hard

so the package-mapper fails because it's not expecting that trailing @^4

I think the fix for this issue will work regardless, but @FrozenPandaz should I make a ticket for this specific problem? Or maybe someone knows why this particular dependency is being weird?

jericopingul commented 1 year ago

Thank you both @meeroslav and @FrozenPandaz for helping resolve this 🎉

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.