Angular升级问题及解决方案记录(v11=>v17)

213 阅读2分钟

初始化虚拟机环境

虚拟机环境:VMware Workstation 17 Pro + Windows10

NodeJs:14.15.4

Angular:"@angular/cli": "11.0.0",

echart:"chart.js": "2.9.4",

DevUI:"ng-devui": "^11.0.0",

Angular-Material:"@angular/material": "11.0.0",

NG-ZORRO:"ng-zorro-antd": "^11.0.0",

ng2charts:"ng2-charts": "2.4.2",

quill:"ngx-quill": "^14.3.0",

升级参考资料:

Angular升级指南

NG-ZORRO升级指南

NG-ZORROv12升级指南

报错:Migration failed: request to registry.npmjs.org/webpack failed

这是由网络原因导致的,解决方案:

1.开启/关闭代理

$ npm config rm proxy   
$ npm config rm https-proxy

2.使用淘宝镜像作为NPM源

npm config set registry [https://registry.npm.taobao.org](https://registry.npm.taobao.org/)

参考资料:StackOverFlow

报错:Please update your Node.js version

升级NodeJS版本即可,完整输出信息为:

The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Node.js version v14.15.4 detected.
The Angular CLI requires a minimum Node.js version of v18.13.

Please update your Node.js version or visit https://nodejs.org/ for additional instructions.

npm install报错

使用npm install -force进行安装,可以忽略依赖冲突和报错强制安装,但这仅仅是解决表面问题,根源问题无法解决。 同时可以使用npm audit fix --force自动修复项目中存在的依赖问题,但可能会导致局面更糟糕。

报错:Error: error:0308010C:digital envelope routines::unsupported

注意,不要使用NodeJs降级的方法,升级是为了升到更高版本,而不是为了降级兼容。

解决方案:弃用旧版openSSL

set NODE_OPTIONS=--openssl-legacy-provider

参考资料:StackOverFlow

报错:[NOT_IMPLEMENTED] /-/npm/v1/security/audits/quick not implemented yet

参考资料:CSDN

如何查看项目目前存在的依赖问题

npx npm-check-updates -u

如何更新@angular/cdk

更新@angular/material即会自动更新cdk

如何选择angular的更新版本

例如从v11更新至v12的时候,可以执行:

npm i @angular/cli@12 --force

会自动更新至v12的最新版本12.2.18

升级至12.0.0则执行

npm i @angular/cli@12.0.0 --force