angular-cli: `npm install` fails with NPM 7
š Bug report
Command (mark with an x
)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Is this a regression?
This bug did not occur a couple of days ago. It doesnāt seem like itās caused by a specific CLI version. It might be caused by some (peer) dependency of a brand-new Angular project which changed its dependencies.
Description
Creating a new Angular project with the Angular CLI (ng new
) fails when using the latest version of npm (7.5.x).
Error message see below.
š¬ Minimal Reproduction
- Install latest version of Angular CLI:
npm install -g @angular/cli@latest
- Install latest version of npm:
npm install -g npm@latest
- Create a new Angular project:
ng new some-app
Step 3 crashes with the below error message.
š„ Exception or Error
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: ng-npm@0.0.0
npm ERR! Found: @angular/compiler-cli@11.2.0-next.0
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"~11.2.0-next.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler-cli@"^11.0.0 || ^11.1.0-next" from @angular-devkit/build-angular@0.1102.0-next.0
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~0.1102.0-next.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /Users/maximilianschwarzmuller/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/maximilianschwarzmuller/.npm/_logs/2021-02-03T21_29_25_647Z-debug.log
ā Package install failed, see above.
The Schematic workflow failed. See above.
š Your Environment
Angular CLI: 11.1.2
Node: 15.4.0
OS: darwin x64
Angular: undefined
...
Ivy Workspace: <error>
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1101.2
@angular-devkit/core 11.1.2
@angular-devkit/schematics 11.1.2
@angular/cli 11.1.2
@schematics/angular 11.1.2
@schematics/update 0.1101.2
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 13
- Comments: 20 (1 by maintainers)
Hi @dgp1130 we have been trying to raise awareness that the peer dependencies installation behavior from npm@7 has an opt-out option for projects that are unfortunately running into problems with it.
While Iām not really familiar with
angular-cli
it seems to me the reported problem is during the bootstrap of a new project, in that case I would recommend shipping a.npmrc
file at the project root level settinglegacy-peer-deps=true
as a quick way to fix the problem.If thatās not really the case, we would really appreciate if the warning message could point users running npm@7 to use the
--legacy-peer-deps
option instead of recommending users to downgrade to a legacy version.Thanks! š
We talked about this issue in our CLI triage meeting, unfortunately thereās a lot of complexity but we think we have a path forward.
The most immediate āsolutionā to this problem is to restrict our
engines
inpackage.json
to disallow NPM 7. This will warn onnpm install
that NPM 7 is not supported, and will outright fail if the user uses--engine-strict
. We will also add a check in theng
CLI to make this an error even for users who donāt use--engine-strict
. I think we already have one for Node, weāll either need to add one for NPM or confirm that it already has this behavior. This will makeng new
,ng update
, andng add
fail with clear error on NPM 7. Weāll need to publish this change to all supported CLI versions, since theyāll all have the same problem. It doesnāt really solve the issue, but it will at least give a more actionable error message. Iām also pinning this issue just to raise awareness about it and head off duplicates.Regarding the
tsickle
problem, the clear solutions are to:tsickle
which supports TS >=4.0. Weāll need to coordinate with the relevant people to get this out, but the advantage of this is that it will fix the issue for users in a backward-compatible way, so users donāt need to update their versions to leverage the fix. This already has an issue in https://github.com/angular/tsickle/issues/1242.tsickle
fromng-packagr
. This was only used to support Closure compilation, which isnāt supported by the Angular framework anymore anyways, so thereās little value in keeping it around. @alan-agius4 already has a PR to remove it. This will fix future versions ofng-packagr
, regardless of what happens totsickle
.Regarding the
@angular/localize
issue: this is a bit more complicated. Packages from Angular framework are published simultaneously, with pinned versions on each other. In this case,@angular/localize@11.1.2
has a pinned peer dep on specifically@angular/compiler@11.1.2
. Generally speaking, peer deps are supposed to be as broad as possible, but since all Angular packages are released at once and managed by the Angular CLI, we expect users to fairly consistently use matching package versions. Historically this has been fine because NPM mostly ignored those peer deps, but now it is trying to validate them and running into conflicts.While we could unpin FW peer deps to use something like
^11.0.0
, that expands a whole swath of possible error states that may arise. Even if we did this going forward, it wouldnāt provide an immediate solution unless we changed all currently supported versions the same way. Itās also important to point out that@angular/localize@11.1.2
was authored with the expectation that it depends on@angular/compiler@11.1.2
, so we have no guarantee that it would work if we gave it@angular/compiler@11.0.9
. Since this problem applies to all FW packages, an extensive amount of testing and bug fixing would be necessary to make this work. As a result, we donāt think this is a viable option atm.Alternatively, this is arguably an NPM 7 bug since there is a solution to dependency resolution which it failed to find. It seems that NPM 7 is picking the latest compatible version of
@angular/localize@^11.0.0
; that happens to be@angular/localize@11.1.2
, which has a peer dep on@angular/compiler@11.1.2
, which is incompatible with the@angular/compiler@11.0.9
defined byng new
in the userāspackage.json
. However, NPM could just pick@angular/localize@11.0.9
, which has a pinned peer dep on@angular/compiler@11.0.9
and satisfies all the requirements. Itās not the absolute latest version, but it satisfies all semvers and is probably the right answer. There is an NPM issue about this using different packages but illustrating the same problem. If NPM can address this in their package resolution logic, then we donāt need to change anything and it will ājust workā.Similarly,
@angular/localize
(andtsickle
) is an optional peer dep which is now being installed by NPM. Iām not sure if this is expected, as the release notes Iāve found donāt seem to mention this case. However, whether it tries to install an optional peer dep or not, it definitely shouldnāt fail because that peer dep couldnāt be resolved, otherwise it isnāt optional. If NPM failed gracefully in these situations, either printing a warning or just carrying on, things would work just fine. There is another NPM issue about this.For right now, our plan is to do nothing about the
@angular/localize
issue and hope NPM fixes it for us. If this is expected behavior on the NPM side, then we can reevaluate what we can do on the Angular side to solve the problem.Totally agree with this. NPM explicitly include options to remain legacy behaviour exactly because of this kind of reasons. The .npmrc file could additionally be generated by the CLI for workspaces for new and upgrades just for the time of transition.
Requiring everyone to downgrade NPM should be the last option to consider, which is not necessary hereā¦
cheers flash ā”
For those who canāt generate new projects with
ng new
and donāt want to change global NPM version, here is a temp solution:cd
to it.mkdir TempAngularProjects
cd TempAngularProjects
npm i npm@6
npx
npx ng new Its-Angulars-Fault --skip-install -p lets-react
cd Its-Angulars-Fault
.npmrc
trick)npm i -f
ng serve
as usualLater if you need to execute other Angular CLI commands that need to be executed in project folder, such as schematics, you can install NPM 6 to your Angular project as a dev dependency:
npm i npm@6.14.11 --save-dev
npx ng add @angular/cdk
@ruyadorno thank you very much for a solution in your comment.