@nomicfoundation/hardhat-ethers与@openzeppelin/hardhat-upgrades ethers版本冲突
解决@nomicfoundation/hardhat-ethers的ethers版本冲突问题
安装@nomicfoundation/hardhat-ethers时出现ethers版本依赖冲突,使用npm update和强制安装操作均无法解决问题,需要更换为兼容版本,以下是明确的版本对应关系和操作步骤:
- 必须使用兼容版本,@nomicfoundation/hardhat-ethers对ethers有严格的peer依赖约束
- 当前兼容版本对应关系:
- @nomicfoundation/hardhat-ethers v3.x → ethers v6.x
- @nomicfoundation/hardhat-ethers v2.x → ethers v5.x
具体操作步骤
- 先卸载现有冲突的包:
npm uninstall ethers @nomicfoundation/hardhat-ethers - 选择对应组合安装:
- 安装v3版本搭配ethers 6:
npm install ethers@6 @nomicfoundation/hardhat-ethers@3 - 或者安装v2版本搭配ethers 5:
npm install ethers@5 @nomicfoundation/hardhat-ethers@2
- 安装v3版本搭配ethers 6:
补充:若项目中还有其他依赖ethers的包,优先选择匹配项目整体依赖的版本组合;也可以查看@nomicfoundation/hardhat-ethers包的package.json文件里的peerDependencies字段,确认官方要求的ethers版本范围。
内容的提问来源于stack exchange,提问作者Shubhankar Banerjee
相关产品推荐
相关产品推荐

