DDecoene
DDecoene

Reputation: 7260

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?

Upvotes: 3

Views: 7691

Answers (3)

Sourav Ghosh
Sourav Ghosh

Reputation: 11

Use the below command:

npm install -D hardhat-deploy

Then, require("hardhat-deploy");.

Upvotes: 1

Namekian
Namekian

Reputation: 41

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.

Upvotes: 2

Oli
Oli

Reputation: 529

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

Upvotes: 2

Related Questions