Adding Hardhat version 2.12.2 to an existing project either manually to the package.json or by executing one of the commands:
npm i hardhat
npm i --save-dev hardhat
yarn add hardhat
yarn add --dev hardhat
Gave the following error:
HardhatError: HH1: You are not inside a Hardhat project.
The error was resolved by adding a file named hardhat.config.js
to the project root directory.
This file can also be added by executing npx hardhat
and then selecting Create an empty hardhat.config.js
.
I think that the error is misleading and it should be something like this:
"HardhatError: HH1: Could not find the file
hardhat.config.js
. Are you not inside a Hardhat project?"
Or something like:
"HardhatError: HH1: You may not be inside a Hardhat project. Ensure running
npx hardhat
at this directory?"
(You can find more on the discussion at: https://github.com/NomicFoundation/hardhat/issues/1400. But it is limited to collaborators now.)