Aller au contenu principal

Updating an Nx projet

attention

Initially written for Angular 8 to Angular 12.

Docs

Sources

Versions

danger

Nx doesn't really follow semver (e.g. breaking change in 8.12.3).

stepchange\@nrwl/workspace\@angular/cliangularngrxtypescript
1major12.3.412.0.112.0.112.0.04.2.4
1none12.2.011.2.1311.2.1411.1.04.0.7
0none12.1.111.2.1311.2.1411.1.04.0.7
0none12.0.811.2.1311.2.1411.0.04.0.7
0none11.6.311.2.1311.2.1411.0.04.0.7
0none11.5.211.2.1311.2.1411.0.04.0.7
0none11.4.011.2.1311.2.1411.0.04.0.7
0major11.3.211.2.1311.2.1411.0.04.0.7
0minor11.2.1211.0.711.2.1410.0.04.0.7
0none11.1.511.0.711.2.1410.0.04.0.7
0major11.0.2011.0.711.2.1410.0.04.0.7
1none10.4.1510.1.710.2.510.0.04.0.7
0none10.3.310.1.710.2.510.0.04.0.7
0major10.2.110.0.810.2.510.0.03.9.9
0none10.1.010.0.810.2.59.1.03.9.9
0major10.0.1310.0.810.2.59.1.03.9.9
1none9.8.09.1.159.1.139.1.03.8.3
0none9.6.09.1.159.1.139.1.03.8.3
0none9.5.19.1.159.1.139.1.03.8.3
0none9.4.59.1.159.1.139.1.03.8.3
0minor9.3.09.1.159.1.139.1.03.8.3
0minor9.2.49.1.159.1.139.0.03.8.3
0none9.1.49.0.79.1.139.0.03.7.7
0major9.0.49.0.79.1.139.0.03.7.7
1minor8.12.118.3.238.2.148.3.03.5.3

Releases

How To

Using ng update in a Nx repository can lead to errors and inconsistencies. Always use nx migrate instead (cf Updating Nx).

You can use the following commands to update all Angular and Nx related dependencies:

# target major version
MAJOR=9
# list related versions to find the more recent minor and patch version
npm show "@nrwl/workspace@~${MAJOR}" version

# target version
NX_VERSION=9.8.0

# Update package.json and generate a migrations.json file
nx migrate "@nrwl/workspace@${NX_VERSION}"
# OR use the following if some packages versions were manually edited in package.json
# nx migrate "@nrwl/workspace@${NX_VERSION}" --from="@nrwl/workspace@${OLD_VERSION},<other packages ...>"

# run migrations (i.e. code & configuration changes) specified in migrations.json
nx migrate --run-migrations=migrations.json 2>&1 | tee nx-migrate-v${NX_VERSION}.log

rm migrations.json
rm nx-migrate-v${NX_VERSION}.log
git add -A
git commit -m "chore: update Nx to ${NX_VERSION}"

# Update other dependencies (e.g. @angular/material)

npm show "@angular/material@~${MAJOR}" version
MAT_VERSION=9.2.4

nx migrate "@angular/material@${MAT_VERSION}"
nx migrate --run-migrations=migrations.json 2>&1 | tee nx-migrate-material-v${MAT_VERSION}.log

rm migrations.json
rm nx-migrate-material-v${MAT_VERSION}.log
git add -A
git commit -m "chore: update angular material to ${MAT_VERSION}"

See nxup in my dotfiles projet for a more advanced script.

Other packages (like ngx-bootstrap & @angular-builders/custom-webpack) don't provide any migration schematic for v9.

Therefore, running nx migrate ngx-bootstrap@6.2.0 (for example) only updates the version number in package.json, without generating a migrations.json file.

Yet, I recommend using nx migrate to update these packages in the future, in case they provide new migrations schematics.