解决 NPM 安装应用出现 ERESOLVE 错误

在使用npm安装包时遇到ERESOLVE错误,主要是由于npm7对依赖管理更严格。可以通过添加--legacy-peer-deps标志来解决此问题,或者删除node_modules和package-lock.json后再尝试。此外,可以使用npx指定npm的6.x版本来避免此问题。
摘要由CSDN通过智能技术生成

在项目里执行 npm i 出现以下错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: project-name@0.0.1
npm ERR! Found: typescript@3.6.3
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"3.6.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@"^3.6.4" from @nestjs/cli@6.12.9
npm ERR! node_modules/@nestjs/cli
npm ERR!   dev @nestjs/cli@"6.12.9" 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 /root/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-03-30T14_18_07_395Z-debug.log

网上搜了一下,是因为NPM从版本7开始在某些方面比之前版本更加严格,改成 npm i --legacy-peer-deps 后解决。

以下是原文:

ERESOLVE issues with npm@7 are common because npm 7.x is more strict about certain things than npm 6.x. Often, the easiest resolution is to pass the --legacy-peer-deps flag to npm (e.g., npm i --legacy-peer-deps) or else use npm@6.

If that doesn't work immediately, perhaps try removing node_modules and package-lock.json first. They will be recreated.

TIP:

You don't need to uninstall npm@7 to use npm@6. Use npx to specify the version of npm instead. For example: npx -p npm@6 npm i --legacy-peer-deps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值