PaulRBerg / hardhat-packager

Hardhat plugin for preparing the contract artifacts and the TypeChain bindings for registry deployment
MIT License
36 stars 5 forks source link

Error HH201: Could not set param noTypechain for task compile because its name is already used. #13

Closed sebastiantf closed 2 years ago

sebastiantf commented 2 years ago
  1. Initialized a new Hardhat Typescript project with npx hardhat --> Create an advanced sample project that uses TypeScript
  2. Ran the installation command from README: yarn add --dev hardhat-packager typechain @typechain/hardhat @typechain/ethers-v5
  3. Running any hardhat task fails with the following error:

    Screenshot 2022-02-16 at 4 47 56 PM
  4. Searching for noTypechain yields the following results:

    Screenshot 2022-02-16 at 4 48 14 PM
  5. Removed @typechain/hardhat from package.json and reinstalled
  6. Works as expected

Looks like some kind of conflict for the @typechain/hardhat package

Related dependencies used:

"devDependencies": {
  "@typechain/ethers-v5": "^9.0.0",
  "@typechain/hardhat": "^4.0.0",
  "ethers": "^5.5.4",
  "hardhat": "^2.8.4",
  "hardhat-packager": "^1.2.1",
  "typechain": "^7.0.0",
}
PaulRBerg commented 2 years ago

This may be related to https://github.com/dethcrypto/TypeChain/discussions/526.

What version of hardhat, typechain and @typechain/ethers-v5 did you use?

sebastiantf commented 2 years ago

Updated the op with the related dependencies

PaulRBerg commented 2 years ago

Yeah this is caused by https://github.com/dethcrypto/TypeChain/discussions/526.

Make sure to follow the peer dependency rules listed in my package.json file. You can't use hardhat-packager with the latest versions of TypeChain (yet). I'm working on a fix as we speak.

PaulRBerg commented 2 years ago

Okay, this should be fixed in v1.3.0.

Let me know if that works for you, @sebastiantf!

sebastiantf commented 2 years ago

Awesome! Working fine now! Thanks!

CJ42 commented 8 months ago

@PaulRBerg I am experiencing the same issue in my repository when upgrading to the latest version of Hardhat 2.20.0 and ethers v6. This is my package.json below:

This is the PR and the file changes where we are experiencing the issue: https://github.com/lukso-network/lsp-smart-contracts/pull/889/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

image
"devDependencies": {
    "@b00ste/hardhat-dodoc": "^0.3.16",
    "@erc725/erc725.js": "0.23.0",
    "@lukso/eip191-signer.js": "^0.2.2",
    "@nomicfoundation/hardhat-toolbox": "^4.0.0",
    "@nomiclabs/hardhat-web3": "^2.0.0",
    "@turbo/gen": "^1.12.3",
    "@typechain/ethers-v6": "^0.5.1",
    "@typechain/hardhat": "^9.1.0",
    "all-contributors-cli": "^6.26.1",
    "dotenv": "^16.0.3",
    "esbuild": "^0.17.15",
    "eslint": "^7.32.0",
    "eslint-config-custom": "*",
    "eth-create2-calculator": "^1.1.5",
    "ethers": "^6.11.0",
    "hardhat": "^2.20.0",
    "hardhat-contract-sizer": "^2.8.0",
    "hardhat-deploy": "^0.11.25",
    "hardhat-deploy-ethers": "^0.4.1",
    "hardhat-gas-reporter": "^1.0.9",
    "hardhat-packager": "^1.4.2",
    "markdown-table-ts": "^1.0.3",
    "npm-run-all": "^4.1.5",
    "pluralize": "^8.0.0",
    "prettier": "^2.8.8",
    "prettier-plugin-solidity": "^1.1.3",
    "rollup-plugin-esbuild": "^5.0.0",
    "solhint": "^3.6.2",
    "ts-node": "^10.2.0",
    "turbo": "latest",
    "typechain": "^8.3.2",
    "typescript": "^5.3.3",
    "unbuild": "^2.0.0",
    "vite-plugin-checker": "^0.5.6",
    "vite-tsconfig-paths": "^4.0.7",
    "web3": "^1.5.2"
  },
  "peerDependencies": {
    "@typechain/hardhat": "9.x",
    "hardhat": "2.x",
    "lodash": "4.x",
    "typechain": "8.x"
  },
CJ42 commented 8 months ago

The reason it was failing is because hardhat-packager uses v6.0.0 of @typechain/hardhat, while my package.json had ^9.1.0 set.

In order to solve this, we had to do the following:

  1. add the following entry in the package.json, to force resolution to only this version.
"resolutions": {
    "@typechain/hardhat": "9.1.0"
  }
  1. set the following preinstall command in the "script": {} section of the package.json:
"scripts": {
    "preinstall": "npx --yes force-resolutions",
     // your other scripts...
}
  1. delete your node_modules (and package-lock.json as well eventually). And re-run npm i

  2. re-run npm i a 2nd time after the new package-lock.json got generated.

After that, you can run the following rg command below to ensure only one dependency of @typechain/hardhat is installed to resolve to. If two version appear (the one as well from hardhat-packager, then it will not work.

rg --no-ignore -l noTypechain node_modules
image

Kudos to @richtera for his help on debugging this issue! 🚀