nrwl / nx

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

Migration to 20 - Cannot read properties of undefined (reading 'cli') #28410

Open mirogajdos opened 1 month ago

mirogajdos commented 1 month ago

Current Behavior

I'm getting migration errors while trying to upgrade to 20 from 19.8.4. It says that workspace is not up to date but I cannot figure out where is the error and how to get workspace up to date.

Expected Behavior

Migration works

GitHub Repo

No response

Steps to Reproduce

  1. Run npx nx migrate latest
  2. Run npm install
  3. Run npx nx migrate --run-migrations

Nx Report

Node : 22.9.0 OS : linux-x64 Native Target : x86_64-linux npm : 10.8.3

nx : 19.8.4 @nx/js : 19.8.4 @nx/jest : 19.8.4 @nx/linter : 19.8.4 @nx/eslint : 19.8.4 @nx/workspace : 19.8.4 @nx/cypress : 19.8.4 @nx/devkit : 19.8.4 @nx/eslint-plugin : 19.8.4 @nx/nest : 19.8.4 @nx/node : 19.8.4 @nx/plugin : 19.8.4 @nx/react : 19.8.4 @nrwl/tao : 19.8.4 @nx/vite : 19.8.4 @nx/web : 19.8.4 @nx/webpack : 19.8.4 typescript : 5.6.3

Local workspace plugins: @home/workspace-plugin

Failure Logs

NX Running migrations from 'migrations.json'

Running the following migrations:

Running migration nx: move-use-daemon-process

NX Failed to run move-use-daemon-process from nx. This workspace is NOT up to date!

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

TypeError: Cannot read properties of undefined (reading 'cli') at isAngularMigration (/home/miro/code/home/apps/node_modules/nx/src/command-line/migrate/migrate.js:1087:15) at executeMigrations (/home/miro/code/home/apps/node_modules/nx/src/command-line/migrate/migrate.js:920:18) at runMigrations (/home/miro/code/home/apps/node_modules/nx/src/command-line/migrate/migrate.js:1009:43) at /home/miro/code/home/apps/node_modules/nx/src/command-line/migrate/migrate.js:1050:19 at async handleErrors (/home/miro/code/home/apps/node_modules/nx/src/utils/handle-errors.js:9:24)

Package Manager Version

No response

Operating System

Additional Information

My nx.json:

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "workspaceLayout": {
    "appsDir": "apps",
    "libsDir": "libs"
  },
  "generators": {
    "@nx/react": {
      "application": {
        "style": "@emotion/styled",
        "linter": "eslint",
        "bundler": "vite",
        "compiler": "swc",
        "unitTestRunner": "none"
      },
      "component": {
        "style": "@emotion/styled"
      },
      "library": {
        "style": "@emotion/styled",
        "linter": "eslint",
        "unitTestRunner": "none"
      }
    }
  },
  "targetDefaults": {
    "build": {
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"],
      "cache": true
    },
    "component-test": {
      "inputs": ["default", "^production"],
      "cache": true
    },
    "e2e": {
      "inputs": ["default", "^production"],
      "cache": true
    },
    "@nx/jest:jest": {
      "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
      "cache": true,
      "options": {
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    },
    "@nx/eslint:lint": {
      "inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
      "cache": true
    }
  },
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "sharedGlobals": ["{workspaceRoot}/.gitlab-ci.yml"],
    "production": [
      "default",
      "!{projectRoot}/cypress/**/*",
      "!{projectRoot}/**/*.cy.[jt]s?(x)",
      "!{projectRoot}/cypress.config.[jt]s",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/src/test-setup.[jt]s"
    ]
  },
  "defaultBase": "main"
}
jahusa02 commented 1 month ago

Same Problem

hannovisagie commented 1 month ago

I also have this issue. Thought I was loosing my mind.

jaysoo commented 1 month ago

@mirogajdos @jahusa02 @hannovisagie Did npm install succeed? It looks like the Nx packages were not updated to v20, so the migration entry is missing in node_modules/nx/migrations.json.

You can try npm install --force as well, as some ESLint plugins did not update their versions so there could be peer dependencies errors/warnings.

jahusa02 commented 1 month ago

@mirogajdos @jahusa02 @hannovisagie Did npm install succeed? It looks like the Nx packages were not updated to v20, so the migration entry is missing in node_modules/nx/migrations.json.

You can try npm install --force as well, as some ESLint plugins did not update their versions so there could be peer dependencies errors/warnings.

It installed successfully. I use pnpm and it didn't report any missing peerDeps.

One thing I noticed everytime when running migrate was the warning that the local project doesn't define a package manger field.

Don't know if that's related or not

mirogajdos commented 1 month ago

Going to v19.8.6 and trying again to v20 solved the issue for me. I believe my installation also passed. I will try on my company's repo on Monday. It has had the same issue. (Also I did update to node 22.10.0 and npm 10.9.0 - removed package-lock.json and clean installed.. I had to run npm i twice as for some reason as it still doesn't get all the deps on the first time after removing lock)