nx icon indicating copy to clipboard operation
nx copied to clipboard

NX fails to run migration moduleResolution: bundler (Angular 19 -> 20)

Open Tim-arts opened this issue 4 months ago • 0 comments

Current Behavior

While running nx migrate --run-migrations, NX fails to migrate this migration

migrations.json

{
  "migrations": [
    {
      "version": "21.2.0-beta.3",
      "requires": { "@angular/core": ">=20.0.0" },
      "description": "Update 'moduleResolution' to 'bundler' in TypeScript configurations. You can read more about this here: https://www.typescriptlang.org/tsconfig/#moduleResolution.",
      "factory": "./src/migrations/update-21-2-0/update-module-resolution",
      "package": "@nx/angular",
      "name": "update-module-resolution"
    }
  ]
}

After printing nx show projects, it generates a list of all our libs as following:

shared--booking-engine--travelers-assignments--components--ph-travelers-assignments-hold-booking-card--feature
shared--booking-engine--customize-your-trip--components--hotel-requests--hotel-requests-selected-list--ui
shared--booking-engine--customize-your-trip--components--activities--activities-modal-filters--feature
shared--booking-engine--customize-your-trip--components--activities--activities-modal-filters--util
shared--booking-engine--travelers-assignments--components--ph-travelers-assignments-info-resum--ui

Every time I delete a library and re-run the migration, it fails on the next file, giving me the feeling that the path might be too long for the migration script

Expected Behavior

The migration would succeed

GitHub Repo

No response

Steps to Reproduce

I haven't test it out on another repo, but our monorepo contains hundreds of implicits libs and we have some very long paths as:

libs/shared/booking-engine/travelers-assignments/components/ph-travelers-assignments-hold-booking-card/feature (the longest we have)

Nx Report

Node           : 24.1.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 10.11.0

nx                     : 21.2.0
@nx/js                 : 21.2.0
@nx/jest               : 21.2.0
@nx/eslint             : 21.2.0
@nx/workspace          : 21.2.0
@nx/angular            : 21.2.0
@nx/cypress            : 21.2.0
@nx/devkit             : 21.2.0
@nx/eslint-plugin      : 21.2.0
@nx/module-federation  : 21.2.0
@nx/rspack             : 21.2.0
@nx/web                : 21.2.0
@nx/webpack            : 21.2.0
typescript             : 5.8.3

---------------------------------------
Nx key licensed packages
Licensed to Nurun.

@nx/s3-cache  : 2.1.0

---------------------------------------
Registered Plugins:
./tools/plugins/implicit-libs.ts
---------------------------------------
Community plugins:
@jsverse/transloco           : 7.6.1
@ngxs/storage-plugin         : 19.0.0
@ngxs/store                  : 19.0.0
@nx/s3-cache                 : 2.1.0
ngx-daterangepicker-material : 6.0.4
---------------------------------------
Cache Usage: 450.54 MB / 46.04 GB

Failure Logs

➜  mtl-ph-frontend git:(tech/PH-14882-upgrade-angular-20) ✗ nx migrate --run-migrations 

 NX   Running 'pnpm install --no-frozen-lockfile' to make sure necessary packages are installed

Lockfile is up to date, resolution step is skipped
Already up to date
. prepare$ husky install
│ husky - install command is DEPRECATED
└─ Done in 219ms
Done in 1s using pnpm v10.11.0

 NX   Running migrations from 'migrations.json'

Running the following migrations:
- @nx/angular: update-module-resolution (Update 'moduleResolution' to 'bundler' in TypeScript configurations. You can read more about this here: https://www.typescriptlang.org/tsconfig/#moduleResolution.)
---------------------------------------------------------

Running migration @nx/angular: update-module-resolution

 NX   Failed to run update-module-resolution from @nx/angular. This workspace is NOT up to date!


 NX   Cannot find configuration for 'shared--booking-engine--travelers-assignments--components--ph-travelers-assignments-hold-booking-card--feature'

Pass --verbose to see the stacktrace.

nx migrate [packageAndVersion]

Creates a migrations file or runs migrations from the migrations file.
- Migrate packages and create migrations.json (e.g., nx migrate @nx/workspace@latest)
- Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.

Positionals:
  packageAndVersion  The target package and version (e.g, @nx/[email protected]).                                                                                                                                           [string]

Options:
      --help                      Show help                                                                                                                                                                               [boolean]
      --version                   Show version number                                                                                                                                                                     [boolean]
      --verbose                   Prints additional information about the commands (e.g., stack traces).                                                                                                                  [boolean]
      --runMigrations             Execute migrations from a file (when the file isn't provided, execute migrations from migrations.json).                                                                                  [string]
      --ifExists                  Run migrations only if the migrations file exists, if not continues successfully.                                                                                      [boolean] [default: false]
      --from                      Use the provided versions for packages instead of the ones installed in node_modules (e.g., --from="@nx/[email protected],@nx/[email protected]").                                                    [string]
      --to                        Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/[email protected],@nx/[email protected]").                                                     [string]
  -C, --createCommits             Automatically create a git commit after each migration runs.                                                                                                           [boolean] [default: false]
      --commitPrefix              Commit prefix to apply to the commit for each migration, when --create-commits is enabled.                                                           [string] [default: "chore: [nx migration] "]
      --interactive               Enable prompts to confirm whether to collect optional package updates and migrations.                                                                                  [boolean] [default: false]
      --excludeAppliedMigrations  Exclude migrations that should have been applied on previous updates. To be used with --from.                                                                          [boolean] [default: false]

Examples:
  migrate latest                                                           Update all Nx plugins to "latest". This will generate migrations.json
  migrate 9.0.0                                                            Update all Nx plugins to "9.0.0". This will generate migrations.json
  migrate @nx/[email protected] --from="@nx/[email protected],@nx/[email protected]"  Update @nx/workspace and generate the list of migrations starting with version 8.0.0 of @nx/workspace and @nx/node, regardless of what is installed
                                                                           locally
  migrate @nx/[email protected] --to="@nx/[email protected],@nx/[email protected]"     Update @nx/workspace to "9.0.0". If it tries to update @nx/react or @nx/angular, use version "9.0.1"
  migrate [email protected]                                           Update another-package to "12.0.0". This will update other packages and will generate migrations.json file
  migrate latest --interactive                                             Collect package updates and migrations in interactive mode. In this mode, the user will be prompted whether to apply any optional package update and
                                                                           migration
  migrate latest [email protected] --exclude-applied-migrations             Collect package updates and migrations starting with version 14.5.0 of "nx" (and Nx first-party plugins), regardless of what is installed locally, while
                                                                           excluding migrations that should have been applied on previous updates
  migrate --run-migrations=migrations.json                                 Run migrations from the provided migrations.json file. You can modify migrations.json and run this command many times
  migrate --run-migrations --create-commits                                Create a dedicated commit for each successfully completed migration. You can customize the prefix used for each commit by additionally setting
                                                                           --commit-prefix="PREFIX_HERE "

Find more information and examples at https://nx.dev/nx/migrate

Error: Command failed: pnpm exec nx _migrate --run-migrations
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:892:11)
    at execSync (node:child_process:964:15)
    at runNxSync (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/utils/child-process.js:35:34)
    at runLocalMigrate (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/command-line/migrate/migrate.js:1122:39)
    at Object.runMigration (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/command-line/migrate/migrate.js:1145:9)
    at Object.handler (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/command-line/migrate/command-object.js:13:68) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 53936,
  stdout: null,
  stderr: null
}

 NX   Command failed: pnpm exec nx migrate --run-migrations

Pass --verbose to see the stacktrace.

nx migrate [packageAndVersion]

Creates a migrations file or runs migrations from the migrations file.
- Migrate packages and create migrations.json (e.g., nx migrate @nx/workspace@latest)
- Run migrations (e.g., nx migrate --run-migrations=migrations.json). Use flag --if-exists to run migrations only if the migrations file exists.

Positionals:
  packageAndVersion  The target package and version (e.g, @nx/[email protected]).                                                                                                                                           [string]

Options:
      --help                      Show help                                                                                                                                                                               [boolean]
      --version                   Show version number                                                                                                                                                                     [boolean]
      --verbose                   Prints additional information about the commands (e.g., stack traces).                                                                                                                  [boolean]
      --runMigrations             Execute migrations from a file (when the file isn't provided, execute migrations from migrations.json).                                                                                  [string]
      --ifExists                  Run migrations only if the migrations file exists, if not continues successfully.                                                                                      [boolean] [default: false]
      --from                      Use the provided versions for packages instead of the ones installed in node_modules (e.g., --from="@nx/[email protected],@nx/[email protected]").                                                    [string]
      --to                        Use the provided versions for packages instead of the ones calculated by the migrator (e.g., --to="@nx/[email protected],@nx/[email protected]").                                                     [string]
  -C, --createCommits             Automatically create a git commit after each migration runs.                                                                                                           [boolean] [default: false]
      --commitPrefix              Commit prefix to apply to the commit for each migration, when --create-commits is enabled.                                                           [string] [default: "chore: [nx migration] "]
      --interactive               Enable prompts to confirm whether to collect optional package updates and migrations.                                                                                  [boolean] [default: false]
      --excludeAppliedMigrations  Exclude migrations that should have been applied on previous updates. To be used with --from.                                                                          [boolean] [default: false]

Examples:
  migrate latest                                                           Update all Nx plugins to "latest". This will generate migrations.json
  migrate 9.0.0                                                            Update all Nx plugins to "9.0.0". This will generate migrations.json
  migrate @nx/[email protected] --from="@nx/[email protected],@nx/[email protected]"  Update @nx/workspace and generate the list of migrations starting with version 8.0.0 of @nx/workspace and @nx/node, regardless of what is installed
                                                                           locally
  migrate @nx/[email protected] --to="@nx/[email protected],@nx/[email protected]"     Update @nx/workspace to "9.0.0". If it tries to update @nx/react or @nx/angular, use version "9.0.1"
  migrate [email protected]                                           Update another-package to "12.0.0". This will update other packages and will generate migrations.json file
  migrate latest --interactive                                             Collect package updates and migrations in interactive mode. In this mode, the user will be prompted whether to apply any optional package update and
                                                                           migration
  migrate latest [email protected] --exclude-applied-migrations             Collect package updates and migrations starting with version 14.5.0 of "nx" (and Nx first-party plugins), regardless of what is installed locally, while
                                                                           excluding migrations that should have been applied on previous updates
  migrate --run-migrations=migrations.json                                 Run migrations from the provided migrations.json file. You can modify migrations.json and run this command many times
  migrate --run-migrations --create-commits                                Create a dedicated commit for each successfully completed migration. You can customize the prefix used for each commit by additionally setting
                                                                           --commit-prefix="PREFIX_HERE "

Find more information and examples at https://nx.dev/nx/migrate

Error: Command failed: /var/folders/fv/2ynfbzwx129b1xqjqzy6shjr0000gq/T/tmp-53847-Brj0N0EzZ2z4/node_modules/.bin/nx _migrate --run-migrations
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:892:11)
    at execSync (node:child_process:964:15)
    at Object.runMigration (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/command-line/migrate/migrate.js:1138:42)
    at Object.handler (/Users/timdhena/sandbox/ph/mtl-ph-frontend/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@[email protected]__@swc+types@_dfb4f31d80251d331f8a53686ee809f9/node_modules/nx/src/command-line/migrate/command-object.js:13:68) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 53867,
  stdout: null,
  stderr: null

Package Manager Version

No response

Operating System

  • [x] macOS
  • [ ] Linux
  • [ ] Windows
  • [ ] Other (Please specify)

Additional Information

No response

Tim-arts avatar Jun 16 '25 15:06 Tim-arts