Skip to content
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

Importing a local solidity file from its package name can fail in unexpected ways when using a monorepo #1500

Closed
alcuadrado opened this issue Jun 1, 2021 · 1 comment · Fixed by #1509
Labels
good-first-issue Good for newcomers. Guidance available if needed type:bug Something isn't working

Comments

@alcuadrado
Copy link
Member

This is a bug report of an edge case that can only happen if you have a hardhat project inside a monorepo, and the hardhat project is also an npm project p.

If a solidity file within p imports another one using import "p/contracts/...", the compilation will fail. The reason for this is that the file ends up with two source names p/contract/... and contracts/....

This only happens within a monorepo, because otherwise require.resolve("p/...") would fail. In a monorepo it resolves because the top node_modules will have a symlink to p.

We should forbid importing a file using its own npm project name. We should tell the user which import to use instead.

This bug can be reproduced like this:

  1. clone https://github.com/alcuadrado/balancer-core-v2 -- it has a faulty import in pkg/pool-weighted/contracts/smart/LiquidityBootstrappingPool.sol
  2. cd into the project
  3. git checkout compilation-bug-reproduction
  4. yarn
  5. cd pkg/pool-weighted
  6. yarn hardhat compile --show-stack-traces --verbose
@alcuadrado alcuadrado added type:bug Something isn't working package:hardhat-core labels Jun 1, 2021
@alcuadrado
Copy link
Member Author

The best place to forbid this kind of imports is probably here: https://github.com/nomiclabs/hardhat/blob/master/packages/hardhat-core/src/internal/solidity/resolver.ts#L94

@alcuadrado alcuadrado added the good-first-issue Good for newcomers. Guidance available if needed label Jun 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good-first-issue Good for newcomers. Guidance available if needed type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant