NPM 学习笔记 【因为版本冲突,angular安装失败的解决方案】

本文记录了在安装Angular时遇到的版本冲突问题,详细介绍了如何通过全局安装特定版本的Angular CLI(@angular/cli@12.0.0)和使用`--legacy-peer-deps`参数来解决依赖冲突。同时,还分享了检查和管理npm版本、配置代理、清理缓存以及启动Angular项目的步骤,包括设置执行策略以避免报错。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 npm i

npm ERR! code ERESOLVE

npm ERR! ERESOLVE could not resolve

npm ERR!

npm ERR! While resolving: @angular-devkit/build-angular@12.0.5

npm ERR! Found: tslint@5.15.0

npm ERR! node_modules/tslint

npm ERR!   dev tslint@"5.15.0" from the root project

npm ERR!

npm ERR! Could not resolve dependency:

npm ERR! peerOptional tslint@"^6.1.0" from @angular-devkit/build-angular@12.0.5 

npm ERR! node_modules/@angular-devkit/build-angular

npm ERR!   dev @angular-devkit/build-angular@"~12.0.0" from the root project    

npm ERR!

npm ERR! Conflicting peer dependency: tslint@6.1.3

npm ERR! node_modules/tslint

npm ERR!   peerOptional tslint@"^6.1.0" from @angular-devkit/build-angular@12.0.5

npm ERR!   node_modules/@angular-devkit/build-angular

npm ERR!     dev @angular-devkit/build-angular@"~12.0.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!

 

因为版本冲突,所以angular安装失败,所以用npm install -g @angular/cli@12.0.0    全局安装angular 特定的版本12.0.0  ,安装成功以后用 npm install --save --legacy-peer-deps     安装npm,问题就解决了。

这个是我再解决这个问题的过程中用到的命令。

Nodejs版本16
cmd                
npm -v         #查看npm的版本
node -v        #查看nodejs的版本
npm config set proxy=http://账号:密码@服务器名:端口号http://账号:密码@
npm config set https-proxy=http://账号:密码@服务器名:端口号@

npm config get cache   #详情参照网页:https://newsn.net/say/npm-cache.html
npm cache clean          #清除缓存#详情参照网页:https://newsn.net/say/npm-cache.html
npm cache clean -f       #强制清除缓存#详情参照网页:https://newsn.net/say/npm-cache.html
npm install -g @angular/cli@12.0.0   #全局安装angular 特定的版本12.0.0
npm install --save --legacy-peer-deps     #强制安装npm #只是在系统部署,或者有新的安装包需要安装的时候执行
ng serve              #用angular启动程序#

 


注:8若报此错误C:\Users\xxx\AppData\Roaming\npm\ng.ps1
①win10系统搜索框输入Windows PowerShell以管理员身份运行
②打开之后输入set-ExecutionPolicy RemoteSigned
③更改权限为A(一定要选择A)
④通过get-ExecutionPolicy 查看当前的状态
⑤最后再次运行项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值