Can an Angular workspace be recovered cleanly when ng update fails mid-run?
0 reputation · 10 Dec 2024, 10:10 UTC
0 reputation · 10 Dec 2024, 10:10 UTC
Angular CLI's ng update rewrites package.json, executes migration schematics, and can modify source files in place. The goal is to establish a dependable recovery procedure for a workspace that ends up partially migrated because an update stopped partway through.
The core constraint is that ng update does not create an automatic snapshot or rollback point before applying changes. Peer dependency conflicts can abort the run or push toward --force, and schematics that already executed may have mutated files, leaving the workspace inconsistent. Schematic behavior also varies across Angular major versions, and monorepos with shared libraries can see cascading failures that single-project guidance does not address.
Given this gap, is committing the workspace to version control before the update the only dependable safety net, or does the CLI offer a supported way to revert a partially applied update? And does ng update --dry-run predict enough of the schematic side effects to plan a recovery in advance?
35275 reputation · 10 Dec 2024, 18:20 UTC
Angular CLI’s ng update does not create a snapshot or rollback point. If it stops mid‑run, the changes it already made to package.json, lockfiles and source files cannot be undone by the CLI itself. The only reliable way to return to a clean state is to restore the workspace from version control taken before the update.
The update command runs migration schematics that mutate the workspace tree in place. Once a schematic writes a file, the CLI has no record of the previous contents to revert. Consequently, a partial run leaves the workspace in an inconsistent state that only an external history (e.g., Git) can repair.
ng update).git checkout <commit‑hash> # or git reset --hard <commit‑hash>
git clean -fdx # remove untracked files, node_modules, dist, etc.
npm ci # uses package‑lock.json exactly as committed
git status # should show no modifications
ng --version # should match the pre‑update toolchain
If you do not have a pre‑update commit or branch, the only safe fallback is to manually inspect git diff (or git status) after the failed run, revert each changed file individually, and then reinstall dependencies. This is error‑prone and not guaranteed to succeed, so having a version‑control snapshot is strongly advised.
Missing diagnostic detail that would change the recommendation: Do you have a pre‑update git commit or branch to restore to?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.