nrwl / nx

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

nx affected throws error when installing `npm:` prefixed package versions #13228

Closed mattlewis92 closed 1 year ago

mattlewis92 commented 1 year ago

Current Behavior

Adding a new package that is a forked version of the original using this syntax:

"eslint-plugin-disable-autofix": "npm:@mattlewis92/eslint-plugin-disable-autofix@3.0.0",

Throws an error when running affected via pnpm nx affected:test

TypeError: Cannot read properties of undefined (reading 'name')
    at getTouchedNpmPackages (/Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/nx@15.1.1/node_modules/nx/src/project-graph/affected/locators/npm-packages.js:24:41)
    at /Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/nx@15.1.1/node_modules/nx/src/project-graph/affected/affected-project-graph.js:31:27
    at Array.reduce (<anonymous>)
    at filterAffected (/Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/nx@15.1.1/node_modules/nx/src/project-graph/affected/affected-project-graph.js:30:52)
    at projectsToRun (/Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/nx@15.1.1/node_modules/nx/src/command-line/affected.js:100:55)
    at Object.<anonymous> (/Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/nx@15.1.1/node_modules/nx/src/command-line/affected.js:29:26)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/mattlewis/Code/clickup/frontend/node_modules/.pnpm/tslib@2.4.0/node_modules/tslib/tslib.js:115:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

It seems the error is thrown here as npmPackage is undefined (one side of the comparison is using eslint-plugin-disable-autofix as the package name and the other is using @mattlewis92/eslint-plugin-disable-autofix):

https://github.com/nrwl/nx/blob/master/packages/nx/src/project-graph/affected/locators/npm-packages.ts#L31-L33

Expected Behavior

Affected doesn't throw an error

Steps to Reproduce

See https://github.com/nrwl/nx-examples/pull/244

https://app.circleci.com/pipelines/github/nrwl/nx-examples/436/workflows/d81d036c-2fd9-400e-a6ef-a1db34e8f499/jobs/2493

Failure Logs

See above

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 16.17.1
   OS   : darwin arm64
   pnpm : 7.9.0

   nx : 15.1.1
   @nrwl/angular : 15.1.1
   @nrwl/cypress : 15.1.1
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.1.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.1.1
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.1.1
   @nrwl/js : 15.1.1
   @nrwl/linter : 15.1.1
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 15.1.1
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.1.1
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.1.1
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.1.1
   @nrwl/web : 15.1.1
   @nrwl/webpack : 15.1.1
   @nrwl/workspace : 15.1.1
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @fortawesome/angular-fontawesome: 0.10.1
         @ngrx/effects: 14.0.2
         @ngrx/entity: 14.0.2
         @ngrx/router-store: 14.0.2
         @ngrx/schematics: 14.0.2
         @ngrx/store: 14.0.2
         @ngrx/store-devtools: 14.0.2
         @rx-angular/cdk: 1.0.0-rc.2
         @rx-angular/state: 1.6.1
         @rx-angular/template: 1.0.0-rc.3
         angular-calendar: 0.30.1
         ngx-bootstrap: 3.2.0
         @compodoc/compodoc: 1.1.18
         @jscutlery/semver: 2.25.2
         @ngneat/spectator: 12.0.1
         @storybook/angular: 6.5.10
         eslint-plugin-ngrx: 2.1.0
         ng-mocks: 14.3.2
         ngx-deploy-npm: 4.0.0
FrozenPandaz commented 1 year ago

@meeroslav Can you take a look at this issue please?

meeroslav commented 1 year ago

Thank you @mattlewis92 for opening the issue. I have a look as soon as possible.

gejustin commented 1 year ago

I encountered this last night as well in a private repo. I created another example repo before I noticed this issue was already open. When Nx is comparing the modifications to the list of npm packages, it expects the package names to match, but in the case of an alias they do not.

In my repo, here is the change object, c from the nx code:

{
  "type": "JsonPropertyModified",
  "path": [
    "dependencies",
    "@myorg/common"
  ],
  "value": {
    "lhs": "npm:@perfective/common@0.8.0",
    "rhs": "npm:@perfective/common@0.8.3"
  }
}

Here is the package meta data contained in npmPackages:

{
  "type": "npm",
  "name": "npm:@myorg/common@npm:@perfective/common",
  "data": {
    "version": "0.8.3",
    "packageName": "@myorg/common@npm:@perfective/common",
    "hash": "5a6137d540fe631b7f38fd80917b0e046dce7d5f5ce9b67a8d33e3372e466824"
  }
}

So for these aliases, pkg.data.packageName === c.path[1] doesn't match anything.

Hopefully this helps.

meeroslav commented 1 year ago

Thank you @gejustin and @mattlewis92 for all the helpful information.

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.