nx migrate is a two-step process:
- Update packages — resolves the new versions of Nx packages and their plugins, updates
package.json, and generates amigrations.jsonfile listing the code transformations to apply. - Apply migrations — runs the transformations listed in
migrations.jsonagainst your source files.
Run
npm install (or your package manager’s install command) after step 1 and before step 2 to install the updated packages.Migration workflow
1
Generate migrations.json
Target the version you want to migrate to. Using This updates
latest resolves the latest stable release:package.json and creates migrations.json.2
Install updated packages
3
Apply the migrations
migrations.json against your workspace files.4
Review and commit the changes
Inspect the file changes produced by the migrations, run your tests, and commit the result.
Arguments
string
The target package and version to migrate to (e.g.,
@nx/workspace@20.0.0, latest, @nx/react@latest).Options
string
Execute code migrations from a file. When no file path is provided, reads from
migrations.json in the current directory.boolean
default:"false"
When using
--run-migrations, continue successfully even if the migrations file does not exist.string
Override the currently installed versions of packages when computing which migrations to run. Useful when the installed versions are not accurate. Accepts a comma-separated list.
string
Override the target versions that the migrator would otherwise calculate. Accepts a comma-separated list.
boolean
default:"false"
Automatically create a git commit after each migration runs. Alias:
-C.string
default:"\"chore: [nx migration] \""
Custom prefix for commit messages when
--create-commits is enabled. Requires --create-commits.boolean
default:"false"
Enable interactive prompts to confirm whether to collect optional package updates and migrations.
boolean
default:"false"
Exclude migrations that should have already been applied in earlier updates. Must be used with
--from.boolean
Print additional information about the migration process.
Examples
How migrations.json works
After runningnx migrate <version>, Nx creates (or updates) a migrations.json file:
migrations.json before running --run-migrations. Each migration is a code transform (similar to a generator) that modifies workspace files.
