简体   繁体   中英

Cannot find module 'hardhat/config' or its corresponding type declarations

I'm setting up a new project with hardhat, using typescript and yarn.

I'm following https://hardhat.org/guides/typescript.html and when I get to the step " We need to apply three changes to your config for it to work with TypeScript: " there is an instruction to update the hardhat.config.js to hardhat.config.ts

The instructions and the example code say to put import { task } from "hardhat/config"; but vscode and the compiler say Cannot find module 'hardhat/config' or its corresponding type declarations.

What am I missing?

Maybe add this import to your hardhat config file?

import { HardhatUserConfig, task } from "hardhat/config";

And be careful to install all necessary types:

import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "hardhat-gas-reporter";
import "solidity-coverage";

I had the same issue as well. I then tried using npm instead of the yarn package manager and the error got resolved.

I'd recommend uninstalling and reinstalling yarn and check if the error gets resolved, or use the npm package manager instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM