NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.03k stars 1.36k forks source link

Artifact not found error right after compilation #2569

Open alcuadrado opened 2 years ago

alcuadrado commented 2 years ago

Nico from balancer shared this error with me

$ hh compile --show-stack-traces
Nothing to compile
Error HH700: Artifact for contract "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/EnumerableSet.sol:EnumerableSet" not found. 

HardhatError: HH700: Artifact for contract "@balancer-labs/v2-solidity-utils/contracts/openzeppelin/EnumerableSet.sol:EnumerableSet" not found. 
    at Artifacts._handleWrongArtifactForFullyQualifiedName (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/artifacts.ts:457:11)
    at Artifacts._getValidArtifactPathFromFullyQualifiedNameSync (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/artifacts.ts:566:19)
    at Artifacts._getArtifactPathSync (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/artifacts.ts:322:19)
    at Artifacts.removeObsoleteArtifacts (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/artifacts.ts:188:16)
    at SimpleTaskDefinition.action (/home/nventuro/bal/v2/node_modules/hardhat/src/builtin-tasks/compile.ts:1377:23)
    at Environment._runTaskDefinition (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:35)
    at Environment.run (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:25)
    at SimpleTaskDefinition.action (/home/nventuro/bal/v2/node_modules/hardhat/src/builtin-tasks/compile.ts:1407:11)
    at Environment._runTaskDefinition (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
    at Environment.run (/home/nventuro/bal/v2/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)

He's getting an HH700 despite nothing being done.

I suspect this is a bug in our build-info clearing logic.

Will update with the list of plugins he is using.

github-actions[bot] commented 2 years ago

This issue is also being tracked on Linear.

We use Linear to manage our development process, but we keep the conversations on Github.

LINEAR-ID: fb369d0b-2187-4ae9-958a-fae624383ce8

alcuadrado commented 2 years ago

Plugins:

"@nomiclabs/hardhat-ethers@npm:^2.0.1":
  version: 2.0.2

"@nomiclabs/hardhat-etherscan@npm:latest":
  version: 2.1.6
LuozhuZhang commented 2 years ago

My friend, i meet the same problem

In the end, I found out that it was because hardhat could not find the contract, so I needed to specify the contract path for it.

Just modify the path in hardhat.config.ts, more information can be found here: https://hardhat.org/config/

Hope to help you

Screen Shot 2022-04-12 at 15 25 23
alcuadrado commented 2 years ago

Thanks, @hedgezhu!

I'm not sure if that can be a solution, as that's the default behavior of Hardhat.

LuozhuZhang commented 2 years ago

That's ok. Let's figure out how to fix this bug

ihorbond commented 2 years ago

This is still not working even with paths specified. Arghhh this is so frustrating. What am I missing ? https://github.com/ihorbond/hardhat-test

fvictorio commented 2 years ago

@ihorbond did you figure that out? The repo you linked doesn't exist anymore.

ihorbond commented 2 years ago

@fvictorio yes there was a separate issue with Windows and glob package that I opened and you already fixed :)

fvictorio commented 2 years ago

Glad to hear that!

github-actions[bot] commented 2 years ago

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

ysqi commented 2 years ago

i meet the same problem, it works after clear cache:

rm -rf cache
rm -rf artifacts
fvictorio commented 2 years ago

@ysqi you can use npx hardhat clean to do that.

mildlycoder commented 1 year ago

I tried doing npx hardhat clean and specifying the paths still not working. has anyone else figured it out yet?

alcuadrado commented 1 year ago

@codantes can you please open a new issue. This one is about an innocuous error that only happens very infrequently, and I suspect yours is a different one.

jtakalai commented 1 year ago

I'm getting this problem in Github Actions specifically, so far haven't been able to consistently reproduce it locally. Even in Github Actions it happens something like half of the time. Really frustrating! Tried running clean (removing artifacts etc.) before hardhat compile, but right after hardhat compile sometimes the artifacts directory just doesn't contain the JSONs that other scripts expect.

jtakalai commented 1 year ago

For me, it helped to downgrade Node.js from 18.16.0 to 18.12.1. I hope I can use the latest Node once this is fixed :)

Akaki2003 commented 9 months ago

@mildlycoder have you figured it out?

tenbits commented 8 months ago

If this happens during the removeObsoleteArtifacts phase, it means the artifact in the cache folder exists, but doesn't exist in artifacts. This is somewhat a rare case, as two conditions must be matched:

So after the compilation, Hardhat tries to clean the obsolete artifacts, that it finds in cache folder, but throws the error as it is not found in artifacts.

The workaround: make sure the cache folder is removed during the cleanup

Desired Hardhat fix: if the artifact can't be found in removeObsoleteArtifacts method, it should be silently skipped, as it was already successfully removed previously.

Akaki2003 commented 8 months ago

in my case it was that the artifact file name was correct but the contract name didn't match the file name

0xprinc commented 3 weeks ago

@ysqi you are my hero :)