Skip to content

Commit 87cd5cd

Browse files
clydindgp1130
authored andcommitted
fix(@angular/cli): workaround npm 7+ peer dependency resolve errors during 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)
1 parent 2adf252 commit 87cd5cd

File tree

1 file changed

+19
-1
lines changed
  • packages/angular/cli/src/commands/update

1 file changed

+19
-1
lines changed

packages/angular/cli/src/commands/update/cli.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,26 @@ export class UpdateCommandModule extends CommandModule<UpdateCommandArgs> {
686686
});
687687
} catch {}
688688

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

0 commit comments

Comments
 (0)