hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Support importing contracts through the current workspace name

Open fvictorio opened this issue 2 years ago • 12 comments
trafficstars

If you have a monorepo, and you have two workspaces A and B, you can import contracts from A in B doing:

import "A/contracts/SomeContract.sol";

But you can't import them from the same workspace:

import "B/contracts/SomeOtherContract.sol";

This never worked for monorepos, but in v2.12.3 we started detecting this situation, and throwing a better error message.

The problem is that this forbids importing hardhat/console.sol if your package is named hardhat (which will happen if you do mkdir hardhat && cd hardhat && npm init -y); see issues #3623 and #3624.

We should just support this in monorepos and stop throwing the error.

fvictorio avatar Jan 31 '23 23:01 fvictorio

Hi! Thanks for responding to me on #3624

Unfortunately the reason you stated is not correct - The name in my package.json is not "solmate" - it's "@uniswap/universal-router"

Interestingly we have multiple git submodules in the root of the folder: solmate and permit2. Since version 2.12.3 hardhat can no longer find solmate but it can still find permit2.

hensha256 avatar Feb 01 '23 09:02 hensha256

Sorry @hensha256, I read your issue quickly and assumed it was also about hardhat/console.sol; I realize now that it isn't.

I think we might have a bug in an (intended) improvement we added in 2.12.3. I'll look into it as soon as I can.

fvictorio avatar Feb 01 '23 12:02 fvictorio

Error HH412: Invalid import hardhat/console.sol from contracts/Token.sol. Trying to import file using the own package's name.

i still dont understand how to solve this issue

uchihaada avatar Apr 02 '23 09:04 uchihaada

@uchihaada see this comment for that specific issue

hensha256 avatar Apr 03 '23 19:04 hensha256

PR created at https://github.com/NomicFoundation/hardhat/pull/4039.

hiroshitashir avatar Jun 17 '23 00:06 hiroshitashir

hey @fvictorio ! Just wondering if theres any update here? Still facing this issue 😢

hensha256 avatar Nov 02 '23 15:11 hensha256

@hensha256 Not yet, but we'll try to prioritize it as soon as we have some bandwidth.

fvictorio avatar Nov 06 '23 17:11 fvictorio

Error HH412: Invalid import hardhat/console.sol from contracts/Token.sol. Trying to import file using the own package's name.

I tried to start my boilerplate for hardhat from the scratch.

0xapp123 avatar Aug 14 '24 14:08 0xapp123

I also had a same issue on 2.22.8 version. You can check my issue here #5603 Plz fix it soon~ 🙏

0xapp123 avatar Aug 14 '24 15:08 0xapp123