15

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:

This is an image of the error

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

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
KelvinIOT
  • 325
  • 1
  • 2
  • 14
  • hmm could be a windows 10 thing. Have you tried installing hardhat globally with the -g option? Does hardhat install get lost when you restart your PC or command prompt? If so, you might need to add to your PATH env var to the directory where hardhat gets installed by default in windows – Harry Papacharissiou Nov 15 '21 at 06:10
  • @HarryPapacharissiou Thanks for a reply, Harry. If i saw correctly, the docs said something about installing Hardhat specifically in your project, to avoid some global conflicts. I'll try this tho. – KelvinIOT Nov 15 '21 at 10:34

10 Answers10

10

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:

  1. Check if the project package.json has hardhat as its dev dependency. If it is not, run npm install --save-dev hardhat or yarn add --dev hardhat
  2. Uninstall any global version of hardhat
  3. Remove node_modules and run npm install or yarn install to install all dependencies.
  4. Try running npx hardhat compile or npx hardhat node to check if it works.
Sudeep
  • 371
  • 3
  • 8
  • 1
    How can I check if hardhat is installed globally? and how can uninstall it? – David Jay Aug 05 '22 at 12:56
  • 2
    @DavidJay Just run `npm uninstall --global hardhat` You can see all your globally installed packages using `npm list --global --depth=0` – Anas Tiour Aug 27 '22 at 12:47
  • I don't understand something.... you just installed hardhat locally then why are you using `npx`. actually for me npm hardhat isn't working. let me know if I am wrong... OR maybe i can rephrase my question as why `npm hardhat` doesn't work even after its local installation.. – Pranshu_Taneja Nov 18 '22 at 18:10
  • I tried all steps. Only 'yarn add --dev hardhat' made my project worked. Not sure why – oldpride Apr 27 '23 at 03:15
3

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

jhonny
  • 805
  • 4
  • 10
1

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
gkubed
  • 1,849
  • 3
  • 32
  • 45
usama musa
  • 11
  • 1
1

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
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
0

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.

fanbyprinciple
  • 554
  • 7
  • 14
0

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
tpanar
  • 1
0

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...

user2475983
  • 1,916
  • 2
  • 13
  • 20
0

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.

Dhruv Godambe
  • 461
  • 3
  • 7
0

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!

-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 ,

  • Alamin Hossen, please don't add _thanks_ as answers. They don't actually provide an answer to the question, and can be perceived as noise by its future visitors. Once you [earn](//meta.stackoverflow.com/q/146472) enough [reputation](/help/whats-reputation), you will gain privileges to [upvote answers](/help/privileges/vote-up) you like. This way future visitors of the question will see a higher vote count on that answer, and the answerer will also be rewarded with reputation points. See [Why is voting important](/help/why-vote). – Ollie Sep 05 '22 at 15:11