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.

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 cant keep creating a new project each time this happens.

I've been stuck for days now and will appreciate any help, Thanks.

:computer: Environment

I'm using: Hardhat, Windows OS

Hi, welcome! :wave:

It seems like a problem about the tool: Hardhat, so why not try to ask the hardhat team? I know they have a discord: https://discord.gg/ArkuKrdbdm

So how about installing hardhat in the global environment by npm install --global hardhat, and maybe you can reopen a new terminal to have a try.

Sure, @Skyge , i already did that.
There wasnt any reply.

Some concerned devs on stackoverflow suggested i install hardhat globally, ill be doing that next.
Thanks for your help... sorry i'm seeing this kinda late.

Do not install Hardhat globally. If you already have installed hardhat globally, please uninstall as the issue might be because of that itself 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/node

This should fix your issue.

2 Likes

Thanks @sudeepb02

  • I've not tried installing hardhat globally...yet :slight_smile:
  • Also hardhat is part of my projects main dependencies... not the devDependencies, don't know if this could be part of the problem.

I'll follow your steps right way, hope it works.
Thanks again.

Ohhhh, thanks for correcting my point.