Reputation: 345
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
Upvotes: 17
Views: 33070
Reputation: 41
I had the same issue on mac, solved it using these commands :
npm install --save-dev hardhat@^2.19.0 @nomicfoundation/hardhat-toolbox@^3.0.0
you can also by initiating a hardhat project on the same directory
Upvotes: 1
Reputation: 1
I did unstalled nodejs and delted all unrequired file and folder related to hardhat from C:\Users\user and reinstalled all thing, it worked for me ,
Upvotes: -1
Reputation: 11
Don't make directories/folder structure manually, instead do it by using mkdir
command from vscode terminal. This way you will not face this HH12 error.
I recently created several DAPPs and I had never faced this problem again.
mkdir Whitelist-Dapp
cd Whitelist-Dapp
mkdir hardhat-files
cd hardhat-files
npm init --yes
npm install --save-dev hardhat
Upvotes: 1
Reputation: 11
I had the same issue. What I did was run the following commands:
npm install --save-dev "hardhat@^2.10.1
npm i @nomicfoundation/hardhat-toolbox
Upvotes: 1
Reputation: 1
I found a way to avoid this issue by typing the commands in the following sequence. I think it has something to do with when you install your Hardhat in the folder.
I am creating my project in the directory called JACKPOT, and then I type the commands in the following order. So far so good.
Frist create your project folder and then switch to it:
PS C:\Users\alanh> mkdir jackpot
PS C:\Users\alanh> cd jackpot
Then, start VS Code in that folder by typing the following command:
PS C:\Users\alanh\jackpot> code .
Then, add Hardhat to your projet and start the project:
PS C:\Users\alanh\jackpot> yarn add --dev hardhat
PS C:\Users\alanh\jackpot> yarn add --dev hardhat
Hope this helps. Cheers!
Upvotes: 0
Reputation: 471
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.
Upvotes: 0
Reputation: 2122
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...
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 790
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.
Upvotes: 0
Reputation: 858
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
Upvotes: 3
Reputation: 431
Do not install Hardhat globally. If you already have installed hardhat globally, please uninstall as the issue might be because of that as mentioned in the error message.
Things you need to do to mitigate this:
npm install --save-dev hardhat
or yarn add --dev hardhat
npm install
or yarn install
to install all dependencies.npx hardhat compile
or npx hardhat node
to check if it works.Upvotes: 14