nrwl / nx

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

Problems when migrating from 12.3.6 to 13.2.3 #7943

Closed danthedaniel closed 2 years ago

danthedaniel commented 2 years ago

Current Behavior

I ran the following commands:

$ npx nx migrate latest # 13.2.3
$ npx nx migrate --run-migrations

And I got the following output

$ npx nx migrate --run-migrations

>  NX  Running 'npm install' to make sure necessary packages are installed

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 

added 411 packages, removed 1205 packages, changed 433 packages, and audited 4351 packages in 29s

349 packages are looking for funding
  run `npm fund` for details

47 vulnerabilities (36 moderate, 11 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

>  NX  Running migrations from 'migrations.json'

Running migration add-target-dependencies

>  NX   NOTE  Target dependencies have been updated in nx.json

  Nx has deprecated strictlyOrderedTargets in favour of targetDependencies.
  Based on your configuration the migration has configured targetDependencies for the following targets: build.
  Read more here: https://nx.dev/core-concepts/configuration

jsxBracketSameLine is deprecated.
Could not format nx.json. Error: "undefined"
Could not format workspace.json. Error: "undefined"
Could not format tsconfig.base.json. Error: "undefined"
Successfully finished add-target-dependencies
---------------------------------------------------------
Running migration set-default-base-if-not-set
Successfully finished set-default-base-if-not-set
---------------------------------------------------------
Running migration 13-0-0-config-locations
Could not format workspace.json. Error: "undefined"
Could not format nx.json. Error: "undefined"
Successfully finished 13-0-0-config-locations
---------------------------------------------------------
Running migration set-parallel-default
Cannot read property 'default' of undefined
Command failed: /var/folders/qz/jzctsv9j131_w26qqvpjnyq00000gn/T/tmp-15021-gmTBF9519jPn/node_modules/.bin/tao migrate --run-migrations

Expected Behavior

I expected the migrations to be applied without errors 😛

Steps to Reproduce

Here are the changes that were applied to my package.json:

diff --git a/package.json b/package.json
index f0e6f4b3..38d4270b 100644
--- a/package.json
+++ b/package.json
@@ -63,7 +63,7 @@
     "@nestjs/typeorm": "7.1.4",
     "@nestjsx/crud": "4.6.2",
     "@nestjsx/crud-typeorm": "4.6.2",
-    "@reduxjs/toolkit": "^1.6.2",
+    "@reduxjs/toolkit": "1.6.2",
     "@segment/snippet": "^4.14.2",
     "@sendgrid/mail": "^7.4.4",
     "@sentry/nextjs": "^6.11.0",
@@ -106,7 +106,7 @@
     "luxon": "^1.27.0",
     "magic-sdk": "^4.3.0",
     "meow": "7.1.1",
-    "next": "^10.2.3",
+    "next": "12.0.0",
     "next-images": "^1.7.0",
     "nx": "12.3.6",
     "passport": "^0.4.1",
@@ -120,8 +120,8 @@
     "react-hot-toast": "^2.0.0",
     "react-hotkeys-hook": "^3.3.1",
     "react-inlinesvg": "^2.3.0",
-    "react-redux": "7.2.1",
-    "react-router-dom": "5.2.0",
+    "react-redux": "7.2.5",
+    "react-router-dom": "5.3.0",
     "react-select": "^4.3.1",
     "react-select-search": "^3.0.7",
     "react-simple-tooltip": "^2.6.3",
@@ -151,54 +151,54 @@
     "@innocells/branch-naming-check": "1.0.0",
     "@nestjs/schematics": "7.2.5",
     "@nestjs/testing": "7.4.4",
-    "@nrwl/cli": "^12.3.6",
-    "@nrwl/cypress": "12.3.6",
-    "@nrwl/eslint-plugin-nx": "12.3.6",
-    "@nrwl/jest": "12.3.6",
-    "@nrwl/nest": "12.3.6",
-    "@nrwl/next": "12.3.6",
-    "@nrwl/node": "12.3.6",
-    "@nrwl/react": "12.3.6",
-    "@nrwl/web": "12.3.6",
-    "@nrwl/workspace": "12.3.6",
+    "@nrwl/cli": "13.2.3",
+    "@nrwl/cypress": "13.2.3",
+    "@nrwl/eslint-plugin-nx": "13.2.3",
+    "@nrwl/jest": "13.2.3",
+    "@nrwl/nest": "13.2.3",
+    "@nrwl/next": "13.2.3",
+    "@nrwl/node": "13.2.3",
+    "@nrwl/react": "13.2.3",
+    "@nrwl/web": "13.2.3",
+    "@nrwl/workspace": "13.2.3",
     "@semantic-release/changelog": "5.0.1",
     "@semantic-release/git": "9.0.0",
     "@semantic-release/github": "7.1.1",
     "@sindresorhus/tsconfig": "0.7.0",
-    "@testing-library/react": "11.1.0",
+    "@testing-library/react": "12.1.2",
     "@types/bcrypt": "^3.0.1",
     "@types/draft-js": "^0.11.5",
     "@types/ink-divider": "2.0.1",
-    "@types/jest": "26.0.15",
+    "@types/jest": "27.0.2",
     "@types/luxon": "^1.26.5",
     "@types/mjml": "^4.7.0",
     "@types/node": "8.10.66",
     "@types/passport": "^1.0.6",
     "@types/passport-jwt": "^3.0.5",
     "@types/pg": "7.14.11",
-    "@types/react": "^16.9.55",
-    "@types/react-dom": "16.9.8",
+    "@types/react": "17.0.30",
+    "@types/react-dom": "17.0.9",
     "@types/react-redux": "7.1.9",
-    "@types/react-router-dom": "5.1.6",
+    "@types/react-router-dom": "5.3.1",
     "@types/supertest": "^2.0.11",
     "@typescript-eslint/eslint-plugin": "4.3.0",
     "@typescript-eslint/parser": "4.3.0",
     "autoprefixer": "^10.2.5",
     "ava": "^3.15.0",
-    "babel-jest": "26.6.1",
+    "babel-jest": "27.2.3",
     "chalk": "4.1.0",
     "commitizen": "^4.2.4",
     "prettier-plugin-import-sort": "0.0.6",
     "semantic-release": "^17.4.2",
     "start-server-and-test": "^1.14.0",
     "supertest": "5.0.0",
     "tailwindcss": "^2.2.7",
-    "ts-jest": "26.4.2",
+    "ts-jest": "27.0.5",
     "ts-node": "9.1.1",
     "tsconfig-paths": "^3.9.0",
     "tslint": "6.1.3",
-    "typescript": "4.3.2",
+    "typescript": "4.3.5",
     "webpack-mjml-loader": "^1.1.0",
     "xo": "^0.44.0"
   },
   "engines": {
     "node": ">=14.13.1 <15.0.0",
-    "npm": ">=6.14.8 <7.0.0"
+    "npm": ">=7.24.2 <8.0.0"
   },
   "importSort": {
     ".js, .jsx, .ts, .tsx": {
@@ -237,3 +237,4 @@
     }
   }
 }

Here are the changes applied to workspace.json:

diff --git a/workspace.json b/workspace.json
index 2c9ef95f..5b29d216 100644
--- a/workspace.json
+++ b/workspace.json
@@ -1,31 +1,5 @@
 {
   "version": 1,
-  "cli": {
-    "defaultCollection": "@nrwl/nest"
-  },
-  "defaultProject": "api",
-  "schematics": {
-    "@nrwl/react": {
-      "application": {
-        "style": "scss",
-        "linter": "eslint",
-        "babel": true
-      },
-      "component": {
-        "style": "scss"
-      },
-      "library": {
-        "style": "scss",
-        "linter": "eslint"
-      }
-    },
-    "@nrwl/next": {
-      "application": {
-        "style": "css",
-        "linter": "eslint"
-      }
-    }
-  },
   "projects": {
     "api": {
       "root": "apps/api",
@@ -88,7 +62,62 @@
             "passWithNoTests": true
           }
         }
-      }
+      },
+      "tags": []
+    },
+    "models": {
+      "root": "libs/models",
+      "sourceRoot": "libs/models/src",
+      "projectType": "library",
+      "schematics": {},
+      "architect": {
+        "lint": {
+          "builder": "@nrwl/linter:lint",
+          "options": {
+            "linter": "eslint",
+            "tsConfig": [
+              "libs/models/tsconfig.lib.json",
+              "libs/models/tsconfig.spec.json"
+            ],
+            "exclude": [
+              "**/node_modules/**",
+              "!libs/models/**/*"
+            ]
+          }
+        },
+        "test": {
+          "builder": "@nrwl/jest:jest",
+          "options": {
+            "jestConfig": "libs/models/jest.config.js",
+            "passWithNoTests": true
+          }
+        }
+      },
+      "tags": []
+    },
+    "validations": {
+      "root": "libs/validations",
+      "sourceRoot": "libs/validations/src",
+      "projectType": "library",
+      "schematics": {},
+      "architect": {
+        "lint": {
+          "builder": "@nrwl/linter:eslint",
+          "options": {
+            "lintFilePatterns": [
+              "libs/validations/**/*.ts"
+            ]
+          }
+        },
+        "test": {
+          "builder": "@nrwl/jest:jest",
+          "options": {
+            "jestConfig": "libs/validations/jest.config.js",
+            "passWithNoTests": true
+          }
+        }
+      },
+      "tags": []
     },
     "webapp": {
       "root": "apps/webapp",
@@ -145,7 +174,8 @@
             ]
           }
         }
-      }
+      },
+      "tags": []
     },
     "webapp-e2e": {
       "root": "apps/webapp-e2e",
@@ -178,59 +208,12 @@
             ]
           }
         }
-      }
-    },
-    "models": {
-      "root": "libs/models",
-      "sourceRoot": "libs/models/src",
-      "projectType": "library",
-      "schematics": {},
-      "architect": {
-        "lint": {
-          "builder": "@nrwl/linter:lint",
-          "options": {
-            "linter": "eslint",
-            "tsConfig": [
-              "libs/models/tsconfig.lib.json",
-              "libs/models/tsconfig.spec.json"
-            ],
-            "exclude": [
-              "**/node_modules/**",
-              "!libs/models/**/*"
-            ]
-          }
-        },
-        "test": {
-          "builder": "@nrwl/jest:jest",
-          "options": {
-            "jestConfig": "libs/models/jest.config.js",
-            "passWithNoTests": true
-          }
-        }
-      }
-    },
-    "validations": {
-      "root": "libs/validations",
-      "sourceRoot": "libs/validations/src",
-      "projectType": "library",
-      "schematics": {},
-      "architect": {
-        "lint": {
-          "builder": "@nrwl/linter:eslint",
-          "options": {
-            "lintFilePatterns": [
-              "libs/validations/**/*.ts"
-            ]
-          }
-        },
-        "test": {
-          "builder": "@nrwl/jest:jest",
-          "options": {
-            "jestConfig": "libs/validations/jest.config.js",
-            "passWithNoTests": true
-          }
-        }
-      }
+      },
+      "tags": [],
+      "implicitDependencies": [
+        "webapp",
+        "api"
+      ]
     }
   },
   "tiptap-extensions": {

Environment

Before:

  Node : 14.17.0
  OS   : darwin arm64
  npm  : 7.24.2

  nx : 12.3.6
  @nrwl/angular : Not Found
  @nrwl/cli : 12.3.6
  @nrwl/cypress : 12.3.6
  @nrwl/devkit : 12.3.6
  @nrwl/eslint-plugin-nx : 12.3.6
  @nrwl/express : Not Found
  @nrwl/jest : 12.3.6
  @nrwl/linter : 12.3.6
  @nrwl/nest : 12.3.6
  @nrwl/next : 12.3.6
  @nrwl/node : 12.3.6
  @nrwl/react : 12.3.6
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.3.6
  @nrwl/web : 12.3.6
  @nrwl/workspace : 12.3.6
  @nrwl/storybook : 12.3.6
  @nrwl/gatsby : Not Found
  typescript : 4.3.2

After:

  Node : 14.17.0
  OS   : darwin arm64
  npm  : 7.24.2

  nx : 12.3.6
  @nrwl/angular : undefined
  @nrwl/cli : 13.2.3
  @nrwl/cypress : 13.2.3
  @nrwl/devkit : 13.2.3
  @nrwl/eslint-plugin-nx : 13.2.3
  @nrwl/express : undefined
  @nrwl/jest : 13.2.3
  @nrwl/linter : 13.2.3
  @nrwl/nest : 13.2.3
  @nrwl/next : 13.2.3
  @nrwl/node : 13.2.3
  @nrwl/nx-cloud : undefined
  @nrwl/react : 13.2.3
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.2.3
  @nrwl/web : 13.2.3
  @nrwl/workspace : 13.2.3
  @nrwl/storybook : 13.2.3
  @nrwl/gatsby : undefined
  typescript : 4.3.5
  rxjs : 6.6.3
  ---------------------------------------
  Community plugins:
danthedaniel commented 2 years ago

I realized that nx migrate latest didn't update the nx package itself, so I did that manually (upgrading nx to 13.2.3) and then ran the migration commands in my post above. The results were the same:

npx nx migrate --run-migrations                                                                                              §  4:09PM  !2028 

>  NX  Running 'npm install' to make sure necessary packages are installed

npm WARN old lockfile 
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile 
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile 

added 410 packages, removed 1205 packages, changed 433 packages, and audited 4350 packages in 28s

349 packages are looking for funding
  run `npm fund` for details

47 vulnerabilities (36 moderate, 11 high)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

>  NX  Running migrations from 'migrations.json'

Running migration add-target-dependencies

>  NX   NOTE  Target dependencies have been updated in nx.json

  Nx has deprecated strictlyOrderedTargets in favour of targetDependencies.
  Based on your configuration the migration has configured targetDependencies for the following targets: build.
  Read more here: https://nx.dev/core-concepts/configuration

jsxBracketSameLine is deprecated.
Could not format nx.json. Error: "undefined"
Could not format workspace.json. Error: "undefined"
Could not format tsconfig.base.json. Error: "undefined"
Successfully finished add-target-dependencies
---------------------------------------------------------
Running migration set-default-base-if-not-set
Successfully finished set-default-base-if-not-set
---------------------------------------------------------
Running migration 13-0-0-config-locations
Could not format nx.json. Error: "undefined"
Could not format workspace.json. Error: "undefined"
Successfully finished 13-0-0-config-locations
---------------------------------------------------------
Running migration set-parallel-default
Cannot read property 'default' of undefined
Command failed: /var/folders/qz/jzctsv9j131_w26qqvpjnyq00000gn/T/tmp-29852-6eGe0wu7M7X5/node_modules/.bin/tao migrate --run-migrations
  Node : 14.17.0
  OS   : darwin arm64
  npm  : 7.24.2

  nx : 13.2.3
  @nrwl/angular : undefined
  @nrwl/cli : 13.2.3
  @nrwl/cypress : 13.2.3
  @nrwl/devkit : 13.2.3
  @nrwl/eslint-plugin-nx : 13.2.3
  @nrwl/express : undefined
  @nrwl/jest : 13.2.3
  @nrwl/linter : 13.2.3
  @nrwl/nest : 13.2.3
  @nrwl/next : 13.2.3
  @nrwl/node : 13.2.3
  @nrwl/nx-cloud : undefined
  @nrwl/react : 13.2.3
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.2.3
  @nrwl/web : 13.2.3
  @nrwl/workspace : 13.2.3
  @nrwl/storybook : 13.2.3
  @nrwl/gatsby : undefined
  typescript : 4.3.5
  rxjs : 6.6.3
  ---------------------------------------
  Community plugins:
danthedaniel commented 2 years ago

When I try to run apps in my workspace I get the error:

$ npx nx run api:build --prod
(node:32508) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'default' of undefined
    at ./node_modules/@nrwl/workspace/src/core/project-graph/project-graph.js:47:77

project-graph.js:47:77:

function createProjectGraphAsync(projectGraphVersion = '5.0') {
    var _a, _b;
    return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
        const nxJson = (0, file_utils_1.readNxJson)();
        const useDaemonProcessOption = (_b = (_a = nxJson.tasksRunnerOptions['default']) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.useDaemonProcess;
        if (useDaemonProcessOption !== true && process.env.NX_DAEMON !== 'true') {
            return projectGraphAdapter('5.0', projectGraphVersion, yield (0, build_project_graph_1.buildProjectGraph)());
        }
        const daemonClient = require('./daemon/client/client');
        if (!(yield daemonClient.isServerAvailable())) {
            yield daemonClient.startInBackground();
        }
        return projectGraphAdapter('5.0', projectGraphVersion, daemonClient.getProjectGraphFromServer());
    });
}

My nx.json file has no tasksRunnerOptions key in it at all.

hajekj14 commented 2 years ago

Same issue

AgentEnder commented 2 years ago

@danthedaniel you mentioned nx.json doesn't have taskRunnerOptions at all, can you paste an anonymized version of it here?

hajekj14 commented 2 years ago

@AgentEnder migration do not add taskRunnerOptions to nx.json, this is diff after migration:

diff --git a/nx.json b/nx.json
index e1ccddad3..92d44e657 100644
--- a/nx.json
+++ b/nx.json
@@ -13,265 +13,40 @@
     "tslint.json": "*",
     "nx.json": "*"
   },
-  "projects": { ... }
+  "targetDependencies": {},
+  "cli": {
+    "defaultCollection": "@nrwl/angular",
+    "analytics": false
+  },
+  "defaultProject": "oms",
+  "generators": {
+    "@nrwl/angular:application": {
+      "style": "scss",
+      "linter": "eslint",
+      "unitTestRunner": "jest",
+      "e2eTestRunner": "cypress"
+    },
+    "@nrwl/angular:library": {
+      "style": "scss",
+      "linter": "eslint",
+      "unitTestRunner": "jest"
+    },
+    "@nrwl/angular:component": {
+      "style": "scss"
     }
   },
-  "targetDependencies": {}
-}
+}

after adding tasksRunnerOptions manually it works OK

"tasksRunnerOptions": {
    "default": {
      "runner": "@nrwl/workspace/tasks-runners/default",
      "options": {
        "cacheableOperations": [
          "build",
          "lint",
          "test",
          "e2e"
        ],
        "parallel": 1
      }
    }
  }
AgentEnder commented 2 years ago

Hey, I just looked into this and it was fixed in https://github.com/nrwl/nx/pull/7814, and will be part of 13.3's release. Thanks for reporting this!

I'm going to close out this issue, since the fix has been merged. Feel free to open a new issue if something else comes up, or let me know if you feel the issue needs to be reopened.

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.