解决步骤
1. 清理 npm 缓存
bash
npm cache clean --force
2. 切换回官方 npm 源
切换到官方源或其他可靠镜像:
bash
# 切换到官方源
npm config set registry https://registry.npmjs.org/
# 或者使用淘宝镜像(通常更稳定)
npm config set registry https://registry.npmmirror.com/
3. 删除已安装的内容
bash
# 删除 node_modules 文件夹
rm -rf node_modules
# 删除 package-lock.json
rm package-lock.json
Windows PowerShell 用以下命令:
powershell
Remove-Item -Recurse -Force node_modules
Remove-Item package-lock.json
4. 重新安装
bash
npm install
如果问题依然存在
如果切换源后仍有问题,可以尝试:
bash
# 使用 --legacy-peer-deps 参数
npm install --legacy-peer-deps
# 或者使用 --force 参数
npm install --force
验证当前源配置
查看当前使用的源:
bash
npm config get registry