Skip to content

Commit

Permalink
fix(@angular/cli): workaround npm 7+ peer dependency resolve errors d…
Browse files Browse the repository at this point in the history
…uring updates

npm 7+ can fail due to it incorrectly resolving peer dependencies that have valid SemVer
ranges during an `ng update`. Update will set correct versions of dependencies within the
package.json file. However, the failing npm package installation will cause the update process
to abort. To workaround these errors, the npm force option is set during package
installation when the npm package manager at version 7.0.0 or greater is used during an update.

Example error:
```
npm ERR! Conflicting peer dependency: @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR!   peer @angular/compiler-cli@"^14.0.0 || ^14.0.0-rc" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~14.0.0-rc.0" from the root project
```

(cherry picked from commit d79176e)
  • Loading branch information
clydin authored and dgp1130 committed May 26, 2022
1 parent 2adf252 commit 87cd5cd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/angular/cli/src/commands/update/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,26 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
});
} catch {}

let forceInstall = options.force;
// npm 7+ can fail due to it incorrectly resolving peer dependencies that have valid SemVer
// ranges during an update. Update will set correct versions of dependencies within the
// package.json file. The force option is set to workaround these errors.
// Example error:
// npm ERR! Conflicting peer dependency: @angular/[email protected]
// npm ERR! node_modules/@angular/compiler-cli
// npm ERR! peer @angular/compiler-cli@"^14.0.0 || ^14.0.0-rc" from @angular-devkit/[email protected]
// npm ERR! node_modules/@angular-devkit/build-angular
// npm ERR! dev @angular-devkit/build-angular@"~14.0.0-rc.0" from the root project
if (
this.context.packageManager.name === PackageManager.Npm &&
this.context.packageManager.version &&
semver.gte(this.context.packageManager.version, '7.0.0', { includePrerelease: true })
) {
logVerbose('NPM 7+ detected -- enabling force option for package installation');
forceInstall = true;
}
const installationSuccess = await this.context.packageManager.installAll(
options.force ? ['--force'] : [],
forceInstall ? ['--force'] : [],
this.context.root,
);

Expand Down

0 comments on commit 87cd5cd

Please sign in to comment.