scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.41k stars 887 forks source link

bug: borken dependency @nomicfoundation/hardhat-chai-matchers #913

Closed ccolorado closed 3 months ago

ccolorado commented 3 months ago

Is there an existing issue for this?

Which method was used to setup Scaffold-ETH 2 ?

npx create-eth@latest

Current Behavior

npx hardhat compile crashes with error:

An unexpected error occurred:

Error: Cannot find module '@nomicfoundation/hardhat-chai-matchers'
- [REDACTED]/hardhat.config.ts
- [REDACTED]/node_modules/hardhat/internal/core/config/config-loading.js
- [REDACTED]/node_modules/hardhat/internal/cli/cli.js
- [REDACTED]/node_modules/hardhat/internal/cli/bootstrap.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/[REDACTED]/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:981:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:177:18)
    at Object.<anonymous> (/[REDACTED]/hardhat.config.ts:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module.m._compile (/[REDACTED]/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Object.require.extensions.<computed> [as .ts] (/[REDACTED]/node_modules/ts-node/src/index.ts:1621:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/[REDACTED]/hardhat.config.ts',
    '/[REDACTED]/node_modules/hardhat/internal/core/config/config-loading.js',
    '/[REDACTED]/node_modules/hardhat/internal/cli/cli.js',
    '/[REDACTED]/node_modules/hardhat/internal/cli/bootstrap.js'
  ]
}

Expected Behavior

Hardhat should be ready to compile.

Steps To Reproduce

having node v20.12.1 (nvm lts)

npx create-eth@latest choose hardhat npx hardhat compile

Anything else?

Tested with node v18.20.4 Generated package.json

{
  "name": "test",
  "scripts": {
    "compile": "npx hardhat compile",
    "deploy": "npx hardhat deploy",
    "flatten": "npx hardhat flatten",
    "fork": "npx hardhat fork",
    "test": "npx hardhat test",
    "postinstall": "husky install",
    "lintcheck-js": "npx prettier --check --ignore-unknown",
    "lintfix-js": "npx prettier --write --ignore-unknown",
    "lintcheck-sol": "npx solhint --disc contracts/**",
    "lintfix-sol": "npx solhint --disc --fix contracts/**",
    "lintcheck": "npm run check-sol && npm run check-js",
    "lintfix": "npm run lintfix-sol && npm run lintfix-js"
  },
  "devDependencies": {
    "@nomicfoundation/hardhat-toolbox": "^5.0.0",
    "@nomiclabs/hardhat-solhint": "^4.0.0",
    "dotenv": "^16.4.5",
    "hardhat-abi-exporter": "^2.10.1",
    "hardhat-contract-sizer": "^2.10.0",
    "hardhat-deploy": "^0.12.4",
    "hardhat-deploy-ethers": "^0.4.2",
    "husky": "~8.0.3",
    "lint-staged": "~13.2.2",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4"
  },
  "dependencies": {
    "@openzeppelin/contracts": "^5.0.2",
    "hardhat": "^2.22.8",
    "hardhat-watcher": "^2.5.0"
  }
}
technophile-04 commented 3 months ago

Hey @ccolorado not sure what are using but this doesn't seem something generated by plain npx create-eth@latest and choosing hardhat as solidity framework. Are you using any extension?

Ideally the packages/hardhat should look like this:

{
  "name": "@se-2/hardhat",
  "version": "0.0.1",
  "scripts": {
    "account": "hardhat run scripts/listAccount.ts",
    "chain": "hardhat node --network hardhat --no-deploy",
    "compile": "hardhat compile",
    "deploy": "hardhat deploy",
    "flatten": "hardhat flatten",
    "fork": "MAINNET_FORKING_ENABLED=true hardhat node --network hardhat --no-deploy",
    "format": "prettier --write ./*.ts ./deploy/**/*.ts ./scripts/**/*.ts ./test/**/*.ts",
    "generate": "hardhat run scripts/generateAccount.ts",
    "hardhat-verify": "hardhat verify",
    "lint": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore ./*.ts ./deploy/**/*.ts ./scripts/**/*.ts ./test/**/*.ts",
    "lint-staged": "eslint --config ./.eslintrc.json --ignore-path ./.eslintignore",
    "test": "REPORT_GAS=true hardhat test --network hardhat",
    "verify": "hardhat etherscan-verify"
  },
  "dependencies": {
    "@openzeppelin/contracts": "~4.8.1",
    "@typechain/ethers-v6": "~0.5.1",
    "dotenv": "~16.0.3",
    "envfile": "~6.18.0",
    "qrcode": "~1.5.1"
  },
  "devDependencies": {
    "@ethersproject/abi": "~5.7.0",
    "@ethersproject/providers": "~5.7.1",
    "@nomicfoundation/hardhat-chai-matchers": "~2.0.3",
    "@nomicfoundation/hardhat-ethers": "~3.0.5",
    "@nomicfoundation/hardhat-network-helpers": "~1.0.6",
    "@nomicfoundation/hardhat-verify": "~2.0.3",
    "@typechain/ethers-v5": "~10.1.0",
    "@typechain/hardhat": "~9.1.0",
    "@types/eslint": "~8",
    "@types/mocha": "~9.1.1",
    "@types/prettier": "~2",
    "@types/qrcode": "~1",
    "@typescript-eslint/eslint-plugin": "~6.7.3",
    "@typescript-eslint/parser": "~6.7.3",
    "chai": "~4.3.6",
    "eslint": "~8.26.0",
    "eslint-config-prettier": "~8.5.0",
    "eslint-plugin-prettier": "~4.2.1",
    "ethers": "~6.10.0",
    "hardhat": "~2.19.4",
    "hardhat-deploy": "~0.11.45",
    "hardhat-deploy-ethers": "~0.4.1",
    "hardhat-gas-reporter": "~1.0.9",
    "prettier": "~2.8.4",
    "solidity-coverage": "~0.8.5",
    "ts-node": "~10.9.1",
    "typechain": "~8.1.0",
    "typescript": "~5.1.6"
  }
}
ccolorado commented 3 months ago

Yeah I think I thinker a little bit with that installation, installing whatever the error message indicated me.
Maybe the issue is local, but I can't imagine what is going on.

So I ran this :

npx create-eth@latest new -s hardhat && cd new && npx hardhat compile || cat package.json

Same error on compileError: Cannot find module '@nomicfoundation/hardhat-chai-matchers' but my package.json is somewhat different. (removed the script section 20+ lines )

{
  "name": "se-2",
  "version": "0.0.1",
  "private": true,
  "workspaces": {
    "packages": [
      "packages/*"
    ]
  },
  "devDependencies": {
    "husky": "~8.0.3",
    "lint-staged": "~13.2.2"
  },
  "packageManager": "yarn@3.2.3",
  "engines": {
    "node": ">=18.17.0"
  }
}
technophile-04 commented 3 months ago

Ohh actually npx hardhat compile won't work since you are at root of monorepo.

npx create-eth@latest new -s hardhat && cd new && yarn compile

also we are using yarn instead of npm. you could run yarn compile (which compiles things in hardhat) or you could first cd packages/hardhat and then run yarn hardhat compile

technophile-04 commented 3 months ago

Closing this for now, but let us know if it still doesn't work