在 Windows 环境下安装 Hardhat 项目依赖时,遇到以下错误:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @nomicfoundation/edr@^0.11.1.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
@nomicfoundation/hardhat-toolbox
引用了不存在的 EDR 版本@nomicfoundation/edr@^0.11.1
版本不存在npm install -g pnpm
# 查看当前镜像源
npm config get registry
# 切换到官方镜像源
npm config set registry https://registry.npmjs.org/
# 验证切换结果
npm config get registry
cd EasySwapContract
pnpm install
# 删除 node_modules 和锁文件
Remove-Item -Recurse -Force node_modules, package-lock.json
# 或使用 PowerShell
if (Test-Path node_modules) { Remove-Item -Recurse -Force node_modules }
if (Test-Path package-lock.json) { Remove-Item package-lock.json }
npm cache clean --force
npm install
npm install --legacy-peer-deps
npm install --force
# 官方镜像源(推荐用于解决版本问题)
npm config set registry https://registry.npmjs.org/
# 阿里云镜像源
npm config set registry https://registry.npmmirror.com/
# 腾讯云镜像源
npm config set registry https://mirrors.cloud.tencent.com/npm/
# 华为云镜像源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# 查看当前镜像源
npm config get registry
# 设置镜像源
npm config set registry <镜像源地址>
# 查看所有配置
npm config list
request to https://registry.npm.taobao.org/hardhat failed, reason: certificate has expired
解决方案:切换到其他镜像源
No matching version found for @nomicfoundation/edr@^0.11.1
解决方案:切换到官方镜像源或移除问题依赖
edr.win32-x64-msvc.node is not a valid Win32 application
解决方案:重新安装依赖或使用 pnpm
ERESOLVE unable to resolve dependency tree
解决方案:使用 --legacy-peer-deps
或 --force
# 1. 检查 Node.js 版本
node --version
# 2. 检查镜像源
npm config get registry
# 3. 清理环境(如有问题)
Remove-Item -Recurse -Force node_modules, package-lock.json
# 4. 安装依赖
npm install
# 或
pnpm install
# 编译合约
npx hardhat compile
# 运行测试
npx hardhat test
注意:本文档基于实际项目经验整理,适用于 Windows 环境下的 Hardhat 项目依赖安装问题排查。