'Error HH12: Trying to use a non-local installation of Hardhat, which is not supported. Please install Hardhat locally using npm or Yarn, and try again
I've been working on a Hardhat project for sometime.
After a while, when I run
npx hardhat node
to start the HH server, I get the error below:

I tried researching the error and found this on the hardhat site
HH12: Hardhat is not installed or installed globally
You tried to run Hardhat from a global installation or not installing it at all. This is not supported.
Please install Hardhat locally using npm or Yarn, and try again.
Funny enough, I created a new HH project and installed everything afresh
then imported my code into the new project and this seemed to solve the problem...
but after sometime, the issue began again.
I can't keep creating a new project each time this happens.
I've been stuck for days now and will appreciate any help.
OS: windows10
Solution 1:[1]
Try to not run hardhat using npx hardhat ..., run it locally using npm hardhat ... or yarn hardhat ..., other thing that can cause this error on windows is the git bash, if you are using the git bash you won't be able to run hardhat in that case try what running it locally with npm or yarn in the cmd
Solution 2:[2]
First thing to check when this error comes up is whether you are running
npx run scripts/deploy.js --network localhost
in the correct path or not. It should run from directory where you have put hardhat.config.js file.
Solution 3:[3]
To fix this problem, go into your terminal and write nvm use 17. It will switch the node back to 17. The problem is that you may have inadvertently updated your hardhat version so you have 2 versions running on your machine.
Solution 4:[4]
You can also check whether traces tell you something (npx hardhat --show-stack-traces). I tried reinstalling nvm, node, searched whole PC for anything that has hardhat within file name and deleted it.
In the end I was missing some packages in my project...
Solution 5:[5]
In my case I had a problem with the package-lock.json
I deleted the package-lock.json file and then ran the command
npm install
That solved the problem for me.
Solution 6:[6]
HH12: Hardhat is not installed or installed globally You tried to run Hardhat from a global installation or not installing it at all. This is not supported.
Please install Hardhat locally using npm or Yarn, and try again.
npm install hardhat
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jhonny |
| Solution 2 | fanbyprinciple |
| Solution 3 | ouflak |
| Solution 4 | user2475983 |
| Solution 5 | Dhruv Godambe |
| Solution 6 | benjamin pieres |
