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
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
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
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)
For me
npm install --save-dev @nomicfoundation/hardhat-toolbox --force
did the trickon 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