最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Hardhat error: Cannot find module '@nomicfoundationhardhat-etherscan' - Stack Overflow

programmeradmin3浏览0评论

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 and package-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 and package-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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

Your 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");
发布评论

评论列表(0)

  1. 暂无评论