[Ethereum] An unexpected error occurred: Error: Cannot find module ‘@nomiclabs/hardhat-waffle’ [Hardhat, openzeppelin]

binance-smart-chaincontract-developmenthardhatopenzeppelinsolidity

I keep getting this error when doing: npx hardhat run scripts/sample-script.js –network testnet. Edited the name of my computer for security reasons. How do I put in the module 'nomiclabs/hardhat-waffle'?

An unexpected error occurred:

Error: Cannot find module '@nomiclabs/hardhat-waffle'
Require stack:
- /Users/Secret/Documents/Code 2 - Hardhat /hardhat.config.js
- /Users/Secret/Documents/Code 2 - Hardhat /node_modules/hardhat/internal/core/config/config-loading.js
- /Users/Secret/Documents/Code 2 - Hardhat /node_modules/hardhat/internal/cli/cli.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/sarhangsaid/Documents/Code 2 - Hardhat /hardhat.config.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/Secret/Documents/Code 2 - Hardhat /hardhat.config.js',
    '/Users/Secret/Documents/Code 2 - Hardhat /node_modules/hardhat/internal/core/config/config-loading.js',
    '/Users/Secret/Documents/Code 2 - Hardhat /node_modules/hardhat/internal/cli/cli.js'
  ]
}

enter image description here

Best Answer

The problem could be that you have not installed the hardhat waffle package. You should do:

npm install -D @nomiclabs/hardhat-waffle ethereum-waffle

then edit the hardhat.config.js file and add

require('nomiclabs/hardhat-waffle');

above the module.exports variable.

Related Topic