admin管理员组文章数量:1401673
Error with Hardhat Clean: Cannot find module '@nomicfoundation/hardhat-etherscan'
I'm encountering an error when trying to clean my Hardhat project workspace:
npx hardhat clean
An unexpected error occurred: Error: Cannot find module '@nomicfoundation/hardhat-etherscan'
What I've tried:
- Installing the missing package:
npm install --save-dev @nomiclabs/hardhat-etherscan
- Deleting
node_modules
andpackage-lock.json
, then running:npm install
- Checking
hardhat.config.js
for incorrect imports
My hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-etherscan");
require("dotenv").config();
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
solidity: "0.8.9",
};
Environment:
- Node.js version: v22.13.1
- Hardhat version: 2.22.19
- OS: Windows
What could be the possible reason for this error, and how can I fix it?
Error with Hardhat Clean: Cannot find module '@nomicfoundation/hardhat-etherscan'
I'm encountering an error when trying to clean my Hardhat project workspace:
npx hardhat clean
An unexpected error occurred: Error: Cannot find module '@nomicfoundation/hardhat-etherscan'
What I've tried:
- Installing the missing package:
npm install --save-dev @nomiclabs/hardhat-etherscan
- Deleting
node_modules
andpackage-lock.json
, then running:npm install
- Checking
hardhat.config.js
for incorrect imports
My hardhat.config.js:
require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-etherscan");
require("dotenv").config();
const SEPOLIA_RPC_URL = process.env.SEPOLIA_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
defaultNetwork: "hardhat",
networks: {
sepolia: {
url: SEPOLIA_RPC_URL,
accounts: [PRIVATE_KEY],
chainId: 11155111,
},
},
etherscan: {
apiKey: ETHERSCAN_API_KEY,
},
solidity: "0.8.9",
};
Environment:
- Node.js version: v22.13.1
- Hardhat version: 2.22.19
- OS: Windows
What could be the possible reason for this error, and how can I fix it?
Share Improve this question asked Mar 23 at 12:48 prajwalprajwal 11 bronze badge1 Answer
Reset to default 0Your code tries to import @nomicfoundation/hardhat-etherscan
on line 2. But the expected package name is @nomiclabs/hardhat-etherscan
(different scope name, before the slash symbol).
updated hardhat-config.js:
// instead of require("@nomicfoundation/hardhat-etherscan");
require("@nomiclabs/hardhat-etherscan");
Also note that the @nomiclabs/hardhat-etherscan
package is deprecated in favor of @nomicfoundation/hardhat-verify
(source). So you might want to use this one instead:
npm install --save-dev @nomicfoundation/hardhat-verify
updated hardhat-config.js:
// instead of require("@nomicfoundation/hardhat-etherscan");
require("@nomicfoundation/hardhat-verify");
本文标签: nodejsHardhat error Cannot find module 39nomicfoundationhardhatetherscan39Stack Overflow
版权声明:本文标题:node.js - Hardhat error: Cannot find module '@nomicfoundationhardhat-etherscan' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744286141a2598888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论