How to handle conflicting @openzeppelin/contracts versions originating from npm packages

I currently import both @account-abstraction v0.6 and v0.7 in my hardhat project, using the following:

"@account-abstraction-06": "git+https://github.com/eth-infinitism/account-abstraction.git#v0.6.0",
"@account-abstraction-07": "git+https://github.com/eth-infinitism/account-abstraction.git#v0.7.0"

@account-abstraction-06 depends on "@openzeppelin/contracts": "^4.2.0",
and
@account-abstraction-07 depends on "@openzeppelin/contracts": "^5.0.0",

Both of these dependencies import OpenZeppelin contracts with the same base path, i.e., @openzeppelin/contracts .
This presents a problem because I cannot simply install both versions of the @openzeppelin/contracts without causing a conflict.
And I cannot use aliases as this would require modifying the source in @account-abstraction-06 and @account-abstraction-07

:1234: Code to reproduce

Create an empty hardhat project

npx hardhat init

add both these dependencies (use yarn)

"@account-abstraction-06": "git+https://github.com/eth-infinitism/account-abstraction.git#v0.6.0",
"@account-abstraction-07": "git+https://github.com/eth-infinitism/account-abstraction.git#v0.7.0",

add this import to Lock.sol
import "@account-abstraction-07/contracts/core/BasePaymaster.sol";
hardhat compile
Compilation will fail with the following error TypeError: Wrong argument count for modifier invocation: 1 arguments given but expected 0.

I think this answer might help. Essentially, you can install both versions with aliases.

@andrewwahid did you figure this one out? I find myself in the same situation as you: libraries that i'm inheriting "base contracts" from using conflicting versions of OZ contracts (with the same import file path). can't modify the source "base contracts" because they're in node_modules.

Hi @trainface have you tried using aliases as @ernestognw suggested ?

This answer assumes that I am directly importing OZ contracts in my project, but the fact is multiple libraries that I use are importing OZ contracts but in different versions, the problem is that hardhat uses only 1 version of OZ during compilation which of course leads to errors

This is actually a hardhat problem that is not relevant to OZ at all

You can understand the issue better from those 2 github issues

@trainface

1 Like