Skip to content

Hardhat compiles npm packages imports using local package's node_modules #5493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewwahid opened this issue Jul 6, 2024 · 1 comment
Closed
Assignees

Comments

@andrewwahid
Copy link

Version of Hardhat

2.22.6

What happened?

When I import contract A.sol from "@npm-package/contracts/A.sol"
if A.sol imports B.sol from "@npm-package2/contracts/B.sol"
I expect that hardhat uses/compiles B.sol using "project/node_modules/@npm-package/node_modules/@npm-package2/contracts/B.sol"
But what happens is that hardhat compiles B.sol using "project/node_modules/@npm-package2/contracts/B.sol", which causes conflicts when multiple npm packages imports same contracts but in different versions

Minimal reproduction steps

  1. Create empty hardhat project
  2. Add these to package.json dependencies
"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",

Please note that account-abstraction-06 depends on @openzeppelin/contracts": "^4.2.0
And account-abstraction-07 depends on @openzeppelin/contracts": "^5.0.0
3. yarn install
4. add import "account-abstraction-07/contracts/core/BasePaymaster.sol"; to Lock.sol
5. hardhat compile
You'll find that compilation fails because it tries to use OZ's Ownable.sol for a different version than the one located in "project/node_modules/account-abstraction-07/node_modules/openzeppelin/contracts/access/Ownable.sol"

Search terms

conflict, versions, compile, imports

@kanej
Copy link
Member

kanej commented Jul 8, 2024

I am closing this as a duplicate of #2811.

This is a known bug that is difficult for us to fix due to the way Hardhat leverages solc in combination with node_modules.

We are currently working on a new major version of Hardhat that properly supports this.

@kanej kanej closed this as completed Jul 8, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Jul 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants