DEV Community

Jeremy Ikwuje for Monierate Engineering Blog

Posted on

Fix: Cannot find module '@nomicfoundation/hardhat-toolbox' Solidity

When you are trying to compile a Solidity contract with npx hardhat compile you may experience getting the error Cannot find module '@nomicfoundation/hardhat-toolbox'.

To fix the error "Cannot find module '@nomicfoundation/hardhat-toolbox'", ensure you install the package by running npm install --save-dev @nomicfoundation/hardhat-toolbox on your project terminal. If an error persist (probably due to dependencies) then install all packages required by the plugin. You can also use yarn to install it.

Open your terminal and install Hardhat Toolbox by running the following command:

npm install --save-dev @nomicfoundation/hardhat-toolbox
Enter fullscreen mode Exit fullscreen mode

If the "Cannot find module '@nomicfoundation/hardhat-toolbox" error is not resolved, try installing all dependencies.

Run the following command to install all dependencies:

npm install --save-dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers
Enter fullscreen mode Exit fullscreen mode

If you prefer to use yarn, the following command will also install all dependencies:

yarn add --dev @nomicfoundation/hardhat-toolbox @nomicfoundation/hardhat-network-helpers @nomicfoundation/hardhat-chai-matchers @nomiclabs/hardhat-ethers @nomiclabs/hardhat-etherscan chai ethers hardhat-gas-reporter solidity-coverage @typechain/hardhat typechain @typechain/ethers-v5 @ethersproject/abi @ethersproject/providers
Enter fullscreen mode Exit fullscreen mode

You can then go ahead compiling your Solidity smart contract.

Conclusion

As explained above, to fix the error "Cannot find module '@nomicfoundation/hardhat-toolbox'", ensure you install the package by running npm install --save-dev @nomicfoundation/hardhat-toolbox on your project terminal. If it still throws an error (probably due to dependencies) then install all packages required by the plugin. You can also use yarn to install all the dependencies.

Top comments (2)

Collapse
 
alexkubica profile image
Alex Kubica ๐Ÿ‡ฎ๐Ÿ‡ฑ

For me npm install --save-dev @nomicfoundation/hardhat-toolbox --force did the trick

Collapse
 
alexkubica profile image
Alex Kubica ๐Ÿ‡ฎ๐Ÿ‡ฑ

on second try --force messed up the ethers package versions
downgrading to toolbox's v2 did the trick, for real this time ๐Ÿ˜‚
โฏ npm install --save-dev @nomicfoundation/hardhat-toolbox@2