nrwl / nx

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

13 Migration: TypeError: Cannot read properties of undefined (reading 'data') #7606

Closed muuvmuuv closed 2 years ago

muuvmuuv commented 2 years ago

Current Behavior

Running nx serve after migrating to 13 produces an error. Could that be because prettier has an incorrect version?

https://github.com/nrwl/nx/blob/master/packages/workspace/src/core/hasher/hasher.ts#L347

Expected Behavior

Steps to Reproduce

Haven't tested yet (going to after setting up a 12 workspace):

  1. setup 12 workspace
  2. migrate to 13
  3. Update some dependencies manually like prettier and eslint
  4. nx serve

Failure Logs

/D/app on  update-workspace [!] via  v16.13.0 at 08:56:25
; pnpm dev

> entergon-workspace@ dev /Users/marvin/Development/app
> nx serve

/Users/marvin/Development/app/node_modules/.pnpm/@nrwl+workspace@13.1.3_prettier@2.4.1+ts-node@10.3.0/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:245
                        res(this.hashing.hashArray([n.data.version]));
                                                      ^

TypeError: Cannot read properties of undefined (reading 'data')
    at ProjectHasher.<anonymous> (/Users/marvin/Development/app/node_modules/.pnpm/@nrwl+workspace@13.1.3_prettier@2.4.1+ts-node@10.3.0/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:245:55)
    at Generator.next (<anonymous>)
    at /Users/marvin/Development/app/node_modules/.pnpm/tslib@2.3.1/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/marvin/Development/app/node_modules/.pnpm/tslib@2.3.1/node_modules/tslib/tslib.js:113:16)
    at /Users/marvin/Development/app/node_modules/.pnpm/@nrwl+workspace@13.1.3_prettier@2.4.1+ts-node@10.3.0/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:240:79
    at new Promise (<anonymous>)
    at ProjectHasher.<anonymous> (/Users/marvin/Development/app/node_modules/.pnpm/@nrwl+workspace@13.1.3_prettier@2.4.1+ts-node@10.3.0/node_modules/@nrwl/workspace/src/core/hasher/hasher.js:240:50)
    at Generator.next (<anonymous>)
    at /Users/marvin/Development/app/node_modules/.pnpm/tslib@2.3.1/node_modules/tslib/tslib.js:117:75

Node.js v17.0.1
 ELIFECYCLE  Command failed with exit code 1.

package.json Diff

diff --git a/package.json b/package.json
index 27945aa9..e82668df 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,7 @@
     "dep-graph": "nx dep-graph"
   },
   "dependencies": {
-    "@agm/core": "^1.1.0",
+    "@agm/core": "^3.0.0-beta.0",
     "@angular/animations": "12.2.9",
     "@angular/common": "12.2.9",
     "@angular/core": "12.2.9",
@@ -38,18 +38,18 @@
     "@angular/router": "12.2.9",
     "@angular/service-worker": "12.2.9",
     "@capacitor-community/contacts": "^1.1.3",
-    "@capacitor/app": "^1.0.3",
-    "@capacitor/browser": "^1.0.3",
-    "@capacitor/camera": "^1.1.0",
-    "@capacitor/core": "^3.2.4",
-    "@capacitor/device": "^1.0.3",
-    "@capacitor/filesystem": "^1.0.3",
-    "@capacitor/keyboard": "^1.1.0",
-    "@capacitor/network": "^1.0.3",
-    "@capacitor/share": "^1.0.4",
-    "@capacitor/splash-screen": "^1.1.3",
-    "@capacitor/status-bar": "^1.0.3",
-    "@capacitor/storage": "^1.2.0",
+    "@capacitor/app": "^1.0.6",
+    "@capacitor/browser": "^1.0.6",
+    "@capacitor/camera": "^1.2.0",
+    "@capacitor/core": "^3.3.0",
+    "@capacitor/device": "^1.0.6",
+    "@capacitor/filesystem": "^1.0.6",
+    "@capacitor/keyboard": "^1.1.3",
+    "@capacitor/network": "^1.0.6",
+    "@capacitor/share": "^1.0.7",
+    "@capacitor/splash-screen": "^1.1.6",
+    "@capacitor/status-bar": "^1.0.6",
+    "@capacitor/storage": "^1.2.3",
     "@fortawesome/fontawesome-pro": "^5.15.4",
     "@ionic-native/android-full-screen": "^5.36.0",
     "@ionic-native/android-permissions": "^5.36.0",
@@ -72,56 +72,56 @@
     "@ionic-native/screen-orientation": "^5.36.0",
     "@ionic-native/splash-screen": "^5.36.0",
     "@ionic-native/sqlite": "^5.36.0",
-    "@ionic/angular": "^5.8.4",
-    "@ionic/core": "^5.8.4",
+    "@ionic/angular": "^5.8.5",
+    "@ionic/core": "^5.8.5",
     "@ionic/pwa-elements": "^3.0.2",
-    "@ionic/storage": "^2.3.1",
-    "@ngneat/transloco": "^3.0.4",
+    "@ionic/storage-angular": "^3.0.6",
+    "@ngneat/transloco": "^3.0.7",
     "@ngneat/transloco-locale": "^3.0.1",
     "@ngneat/transloco-persist-translations": "^3.0.1",
     "@ngneat/transloco-preload-langs": "^3.0.2",
-    "@sentry/angular": "^6.13.3",
+    "@sentry/angular": "^6.14.0",
     "@sentry/capacitor": "^0.4.0",
-    "@sentry/tracing": "^6.13.3",
+    "@sentry/tracing": "^6.14.0",
     "@swimlane/ngx-datatable": "^20.0.0",
     "@zxing/browser": "0.0.9",
     "@zxing/library": "^0.18.6",
     "@zxing/ngx-scanner": "^3.2.0",
     "animate.css": "^4.1.1",
-    "com-sarriaroman-photoviewer": "1.1.18",
+    "com-sarriaroman-photoviewer": "^1.2.5",
     "cordova-open-native-settings": "^1.5.5",
     "cordova-plugin-android-permissions": "^1.1.2",
     "cordova-plugin-badge": "^0.8.8",
-    "cordova-plugin-camera": "^4.1.0",
+    "cordova-plugin-camera": "^6.0.0",
     "cordova-plugin-device": "^2.0.3",
-    "cordova-plugin-document-viewer": "0.9.10",
+    "cordova-plugin-document-viewer": "^1.0.0",
     "cordova-plugin-email-composer": "^0.9.2",
     "cordova-plugin-file": "^6.0.2",
-    "cordova-plugin-file-transfer": "github:sitewaerts/cordova-plugin-file-transfer",
+    "cordova-plugin-file-transfer": "^1.7.1",
     "cordova-plugin-fullscreen": "^1.3.0",
     "cordova-plugin-globalization": "^1.11.0",
     "cordova-plugin-google-analytics": "^1.9.0",
-    "cordova-plugin-inappbrowser": "^4.1.0",
+    "cordova-plugin-inappbrowser": "^5.0.0",
     "cordova-plugin-insomnia": "^4.3.0",
     "cordova-plugin-local-notification": "^0.9.0-beta.2",
-    "cordova-plugin-network-information": "^2.0.2",
+    "cordova-plugin-network-information": "^3.0.0",
     "cordova-plugin-screen-orientation": "^3.0.2",
-    "cordova-plugin-simple-image-resizer": "github:JoschkaSchulz/cordova-plugin-image-resizer#v0.2.0",
+    "cordova-plugin-simple-image-resizer": "^0.2.0",
     "cordova-plugin-splashscreen": "^6.0.0",
     "cordova-plugin-whitelist": "^1.3.5",
     "cordova-sqlite-storage": "^6.0.0",
     "cordova-windows": "^7.0.1",
-    "core-js": "^2.6.12",
+    "core-js": "3.16.0",
     "dayjs": "^1.10.7",
     "es6-promise-plugin": "^4.2.2",
     "hash-wasm": "^4.9.0",
     "info.protonet.imageresizer": "0.1.1",
-    "ionicons": "^5.5.3",
+    "ionicons": "^5.5.4",
     "localforage": "^1.10.0",
     "lodash-es": "^4.17.21",
     "merge-images": "^2.0.0",
     "ng-in-viewport": "^6.1.5",
-    "ngx-extended-pdf-viewer": "^10.5.0-alpha.0",
+    "ngx-extended-pdf-viewer": "^10.5.0",
     "ngx-pinch-zoom": "^2.6.2",
     "phonegap-plugin-barcodescanner": "^8.1.0",
     "plyr": "^3.6.9",
@@ -148,62 +148,61 @@
     "@angular/compiler-cli": "12.2.9",
     "@angular/language-service": "12.2.9",
     "@capacitor-community/electron": "^4.0.3",
-    "@capacitor/android": "^3.2.4",
-    "@capacitor/cli": "^3.2.4",
-    "@capacitor/ios": "^3.2.4",
+    "@capacitor/android": "^3.3.0",
+    "@capacitor/cli": "^3.3.0",
+    "@capacitor/ios": "^3.3.0",
     "@compodoc/compodoc": "^1.1.15",
-    "@ionic/angular-toolkit": "^4.0.0",
-    "@ionic/cli": "^6.17.1",
-    "@nrwl/angular": "12.10.0",
-    "@nrwl/cli": "12.10.0",
-    "@nrwl/cypress": "12.10.0",
-    "@nrwl/devkit": "12.10.0",
-    "@nrwl/eslint-plugin-nx": "12.10.0",
-    "@nrwl/jest": "12.10.0",
-    "@nrwl/linter": "12.10.0",
-    "@nrwl/tao": "12.10.0",
-    "@nrwl/workspace": "12.10.0",
+    "@ionic/angular-toolkit": "^5.0.0",
+    "@ionic/cli": "^6.18.0",
+    "@nrwl/angular": "13.1.3",
+    "@nrwl/cli": "13.1.3",
+    "@nrwl/cypress": "13.1.3",
+    "@nrwl/devkit": "13.1.3",
+    "@nrwl/eslint-plugin-nx": "13.1.3",
+    "@nrwl/jest": "13.1.3",
+    "@nrwl/linter": "13.1.3",
+    "@nrwl/tao": "13.1.3",
+    "@nrwl/workspace": "13.1.3",
     "@nxtend/capacitor": "^11.1.1",
     "@nxtend/ionic-angular": "^11.1.1",
-    "@sentry/cli": "^1.69.1",
-    "@sentry/webpack-plugin": "^1.18.0",
-    "@testing-library/angular": "^10.11.0",
-    "@testing-library/jest-dom": "^5.14.1",
+    "@sentry/cli": "^1.71.0",
+    "@sentry/webpack-plugin": "^1.18.3",
+    "@types/google.maps": "^3.46.0",
     "@types/jest": "27.0.2",
     "@types/lodash-es": "^4.17.5",
-    "@types/node": "^14.17.18",
-    "@types/semver": "^7.3.8",
+    "@types/node": "^16.11.6",
+    "@types/semver": "^7.3.9",
     "@types/webpack": "^5.28.0",
     "@typescript-eslint/eslint-plugin": "^5.3.0",
     "@typescript-eslint/parser": "^5.3.0",
     "cordova": "^10.0.0",
     "cross-env": "^7.0.3",
-    "cypress": "^8.6.0",
-    "dotenv": "10.0.0",
-    "eslint": "7",
-    "eslint-config-prettier": "8.3.0",
+    "cypress": "^8.7.0",
+    "dotenv": "^10.0.0",
+    "eslint": "^8.1.0",
+    "eslint-config-prettier": "^8.3.0",
     "eslint-import-resolver-typescript": "^2.5.0",
     "eslint-plugin-cypress": "^2.12.1",
     "eslint-plugin-import": "^2.25.2",
     "eslint-plugin-prettier": "^4.0.0",
     "eslint-plugin-unicorn": "^37.0.1",
     "execa": "^5.1.1",
-    "jest": "27.2.5",
-    "jest-preset-angular": "10.0.1",
+    "jest": "27.3.1",
+    "jest-preset-angular": "10.1.0",
     "jetifier": "^2.0.0",
-    "jira-client": "^6.22.0",
+    "jira-client": "^6.23.0",
     "kleur": "^4.1.4",
     "prettier": "2.4.1",
-    "stylelint": "14.0.1",
+    "stylelint": "^14.0.1",
     "stylelint-config-prettier": "^9.0.3",
     "stylelint-config-recess-order": "^2.5.0",
-    "stylelint-config-recommended-scss": "5.0.0",
+    "stylelint-config-recommended-scss": "^5.0.1",
     "stylelint-config-standard": "^23.0.0",
     "stylelint-order": "^5.0.0",
     "stylelint-prettier": "^1.2.0",
     "stylelint-scss": "^4.0.0",
     "ts-custom-error": "^3.2.0",
-    "ts-jest": "27.0.5",
+    "ts-jest": "27.0.7",
     "ts-node": "10.3.0",
     "typescript": "4.3.5",
     "webpack": "5.50.0"

Environment

>  NX  Report complete - copy this into the issue template

  Node : 16.13.0
  OS   : darwin arm64
  pnpm : 6.19.1

  nx : 13.1.3
  @nrwl/angular : 13.1.3
  @nrwl/cli : 13.1.3
  @nrwl/cypress : 13.1.3
  @nrwl/devkit : 13.1.3
  @nrwl/eslint-plugin-nx : 13.1.3
  @nrwl/express : Not Found
  @nrwl/jest : 13.1.3
  @nrwl/linter : 13.1.3
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/nx-cloud : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 13.1.3
  @nrwl/web : Not Found
  @nrwl/workspace : 13.1.3
  @nrwl/storybook : 13.1.3
  @nrwl/gatsby : Not Found
  typescript : 4.3.5
muuvmuuv commented 2 years ago

Seems a remove of node_modules fixed the problem

afraser commented 2 years ago

nx clear-cache

elucidsoft commented 1 year ago

Ok so I have been having this issue lately, before I never had it all. It's very odd. The only way I have found to resolve it is to use to remove package-lock.json, and node_modules/ folder and then running npm i. I tried nx clear-cache, I tried deleting ONLY the node_modules/ folder and running npm i but none of that worked.

jamie-wearsafe commented 1 year ago

issue seems to be yocto-queue

in npm-packages.js I updated it to print the issue:

const npmPackage = npmPackages.find((pkg) => {
                console.log(`${pkg.data.packageName} === ${c.path[1]}`, pkg.data, c.path);
                return pkg.data.packageName === c.path[1];
              }
                );
              console.log('npmPackage', npmPackage);

the last thing it prints is:

yocto-queue === eslint-plugin-import {
  version: '0.1.0',
  packageName: 'yocto-queue',
  hash: '1acee86624de498294338c33ed08242cc253872a79dffd778f2287b144fbd853'
} [ 'devDependencies', 'eslint-plugin-import' ]
npmPackage undefined
nx.js affected

TypeError: Cannot read properties of undefined (reading 'name')
    at getTouchedNpmPackages (/actions-toolkit/node_modules/nx/src/project-graph/affected/locators/npm-packages.js:30:39)
zoix commented 1 year ago

I don't know if this is relevant or useful for somebody else.

Something similar happened to me with wagmi and yarn. The exact same output happened specifically after installing that package (so probably some other packages are presenting the same behaviour).

Nothing worked other than switching to npm. Not the best solution but it works in the meantime.

roninjin10 commented 1 year ago

@zoix I got repro of this too

mkieblesz commented 1 year ago

For me the issue is fixed by downgrading from 15.3 to 15.2. Unfortunatelly didn't spend much time trying to figure out what was wrong. If I will find the problem I will post it here

liammurray commented 1 year ago

I could not get any of the above to work even after removing node_modules and package-lock.json. No matter what nx command I type, it just prints "Cannot read properties of undefined (reading 'data')". There is no useful stack trace or any other information (does nx have a verbose mode?). The only thing that worked for me was to migrate to 15.2.4 (instead of 15.3.3)

bart-vandervliet commented 1 year ago

Same here. Reverting to 15.2.4 solved the issue.

mkieblesz commented 1 year ago

Started working again after upgrading to 15.4.4.

w90 commented 1 year ago

I have the same exact thing

w90 commented 1 year ago

 >  NX   Cannot read properties of undefined (reading 'data')

HookWebpackError: Cannot read properties of undefined (reading 'data')
    at makeWebpackError (/workspace-dir/node_modules/webpack/lib/HookWebpackError.js:48:9)
    at /workspace-dir/node_modules/webpack/lib/Compilation.js:3060:12
    at eval (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:95:1)
    at fn (/workspace-dir/node_modules/webpack/lib/Compilation.js:480:17)
    at _next0 (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:93:1)
    at eval (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:106:1)
    at eval (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
-- inner error --
TypeError: Cannot read properties of undefined (reading 'data')
    at pathLengthToIncoming (/workspace-dir/node_modules/nx/src/lock-file/project-graph-pruning.js:128:37)
    at /workspace-dir/node_modules/nx/src/lock-file/project-graph-pruning.js:97:34
    at Array.forEach (<anonymous>)
    at /workspace-dir/node_modules/nx/src/lock-file/project-graph-pruning.js:96:25
    at Map.forEach (<anonymous>)
    at rehoistNodes (/workspace-dir/node_modules/nx/src/lock-file/project-graph-pruning.js:87:23)
    at pruneProjectGraph (/workspace-dir/node_modules/nx/src/lock-file/project-graph-pruning.js:17:5)
    at createLockFile (/workspace-dir/node_modules/nx/src/lock-file/lock-file.js:112:75)
    at /workspace-dir/node_modules/@nrwl/webpack/src/plugins/generate-package-json-plugin.js:43:131
    at fn (/workspace-dir/node_modules/webpack/lib/Compilation.js:478:10)
    at _next0 (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:93:1)
    at eval (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:106:1)
    at eval (eval at create (/workspace-dir/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
anogr commented 1 year ago

Same problem here after upgrade to 15.7.2

NX Cannot read properties of undefined (reading 'data')

HookWebpackError: Cannot read properties of undefined (reading 'data')

amir-khoshbakht commented 1 year ago

In all these years, NX is by far the worst library I have ever worked with. Not even once has it worked without problems. It is interesting that even the project that works today may fail tomorrow without any changes and waste hours of your time to find the problem.

karol-f commented 1 year ago

In all these years, NX is by far the worst library I have ever worked with

Definitely do not agree. Works fine for me.

Can you create reproduction repository with such error?

amir-khoshbakht commented 1 year ago

In all these years, NX is by far the worst library I have ever worked with

Definitely do not agree. Works fine for me.

Can you create reproduction repository with such error?

Yes, because it is much easier to count its advantages than its disadvantages Does the fact that it works well for you mean that it works well for others? The easiest way to find out the reality of this issue is to use it only a few times and measure the time it takes to fix its problems.

Can you create a reproduction repository with such an error? No. A few months ago I reported a bug from NX that still persists. NX is one of those libraries that prefers to add new features instead of fixing bugs.

brandoncollins7 commented 1 year ago

This is happening with pnpm v8 lockfile version 6

Kolahzary commented 1 year ago

This issue is still happening! I'm using latest stable version of NX and PNPM

NX An error occurred while creating pruned lockfile.

Please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.
To prevent the build from breaking, we are returning the root lock file.

Original error: Cannot read properties of undefined (reading 'data')

TypeError: Cannot read properties of undefined (reading 'data')
at findNodeMatchingVersion (/home/user/Workspace/repos/project/node_modules/.pnpm/nx@15.8.6_@swc+core@1.3.41/node_modules/nx/src/lock-file/project-graph-pruning.js:55:75)
at /home/user/Workspace/repos/project/node_modules/.pnpm/nx@15.8.6_@swc+core@1.3.41/node_modules/nx/src/lock-file/project-graph-pruning.js:35:22
at Array.forEach (<anonymous>)
at normalizeDependencies (/home/user/Workspace/repos/project/node_modules/.pnpm/nx@15.8.6_@swc+core@1.3.41/node_modules/nx/src/lock-file/project-graph-pruning.js:26:42)
at pruneProjectGraph (/home/user/Workspace/repos/project/node_modules/.pnpm/nx@15.8.6_@swc+core@1.3.41/node_modules/nx/src/lock-file/project-graph-pruning.js:13:34)
at createLockFile (/home/user/Workspace/repos/project/node_modules/.pnpm/nx@15.8.6_@swc+core@1.3.41/node_modules/nx/src/lock-file/lock-file.js:128:79)
at /home/user/Workspace/repos/project/node_modules/.pnpm/@nrwl+webpack@15.8.6_@babel+core@7.21.3_@swc+core@1.3.41_@types+node@18.15.5_esbuild@0.16.3_e_gvqnucmt2z3seuptjrodxr2vsi/node_modules/@nrwl/webpack/src/plugins/generate-package-json-plugin.js:42:131
at fn (/home/user/Workspace/repos/project/node_modules/.pnpm/webpack@5.76.2_@swc+core@1.3.41_esbuild@0.16.3/node_modules/webpack/lib/Compilation.js:478:10)
at Hook.eval [as callAsync] (eval at create (/home/user/Workspace/repos/project/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:20:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/home/user/Workspace/repos/project/node_modules/.pnpm/tapable@2.2.1/node_modules/tapable/lib/Hook.js:18:14)
DreadfulBot commented 1 year ago

nx injects too way deep into next js, and works horrible :(

DreadfulBot commented 1 year ago

spent almost 2 days to find out that output:standalone is completely broken, and those withNx plugins for next.config.js don't work properly...

madipta commented 1 year ago

having same problem after upgrading to 16.3.2

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.