Search code examples
hardhat

Npx hardhat could not determine executable to run


I am trying to follow this guide and I am struggling running hardhat. After following the commands in the article:

mkdir hardhat-tutorial
cd hardhat-tutorial
npm init --yes
npm install --save-dev hardhat
npx hardhat

I get an error stating npm ERR! could not determine executable to run. The hardhat tool can be run by navigating to the npm_modules/hardhat directory however this seems to be interfering with the commands later in the tutorial due to the tool being in a different directory to the files it is being used on.

I'm not sure if I have fundamentally misunderstood how hardhat is supposed to work. Are you supposed to install it in each project and have your project directory be within npm_modules/hardhat or have I messed up the install/configuartion?

There appears to have already been a question covering this issue but sadly it was deleted and I have not managed to find another solution.


Solution

  • I had the same issue then it worked for me by specifying the latest version of hardhat during the install, eg.:

    npm install --save-dev "hardhat@^2.8.0"
    

    With this no need to go into the node_modules/hardhat folder in order to run npx hardhat