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");