Angular 报错: Package '@angular/cli' is not a dependency
版本:
$ node -v
v16.14.2
$ npm -v
8.6.0
$ ng version
Angular CLI: 13.3.6
Node: 16.14.2
Package Manager: yarn 1.22.18
OS: darwin x64
Angular: 13.3.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
问题:
执行更新时报错:
$ ng update
$ ng update @angular/cli @angular/core ng-zorro-antd
Using package manager: 'yarn'
Collecting installed dependencies...
Found 0 dependencies.
Package '@angular/cli' is not a dependency.
解决:
目录 node_modules 不存在:
install yarn and angular/cli:
$ npm install -g yarn
$ npm install -g @angular/cli
then install dependencies:
$ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: admin2@0.0.1
npm ERR! Found: @angular-devkit/build-angular@13.2.6
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~13.3.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! dev @angular-devkit/build-angular@"~13.3.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@13.3.8
npm ERR! node_modules/@angular/core
npm ERR! peer @angular/core@"13.3.8" from @angular/service-worker@13.3.8
npm ERR! node_modules/@angular/service-worker
npm ERR! peerOptional @angular/service-worker@"^13.0.0 || ^13.3.0-rc.0" from @angular-devkit/build-angular@13.3.5
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"~13.3.5" 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/wangtom/.npm/eresolve-report.txt for a full report.
then I run npm install command with --force
param:
$ npm install --force