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

Hardhat compile yielding no results, not even a "Nothing to compile" message. #4085

Closed
yvasilyev92 opened this issue Jun 29, 2023 · 25 comments
Closed
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@yvasilyev92
Copy link

Version of Hardhat

2.12.1

What happened?

Earlier today yarn hardhat compile was working fine.

Now when I run it I get no results at all, and no changes to local hardhat.config.ts file or package.json was made.
I tried opening an example hardhat typescript project and yarn hardhat compile works fine, however with my original repo no such luck.

I ran yarn hardhat compile --verbose and this is the result:

hardhat:core:hre Running task compile:solidity:handle-compilation-jobs-failures +6ms
hardhat:core:hre Running task compile:solidity:filter-compilation-jobs +1ms
hardhat:core:tasks:compile force flag enabled, not filtering +172ms
hardhat:core:hre Running task compile:solidity:merge-compilation-jobs +0ms
hardhat:core:hre Running task compile:solidity:compile-jobs +15ms
hardhat:core:hre Running compile:solidity:compile-jobs's super +0ms
hardhat:core:tasks:compile Compiling 1 jobs +15ms
hardhat:core:hre Running task compile:solidity:compile-job +1ms
hardhat:core:tasks:compile Compiling job with version '0.8.13' +1ms
hardhat:core:hre Running task compile:solidity:get-compiler-input +0ms
hardhat:core:hre Running compile:solidity:get-compiler-input's super +0ms
hardhat:core:hre Running task compile:solidity:compile +1ms
hardhat:core:hre Running compile:solidity:compile's super +0ms
hardhat:core:hre Running task compile:solidity:solc:compile +0ms
hardhat:core:hre Running task compile:solidity:solc:get-build +0ms
hardhat:core:tasks:compile Native solc binary doesn't work, using solcjs instead. Try running npx hardhat clean --global +5ms
hardhat:core:hre Running task compile:solidity:log:run-compiler-start +4ms
hardhat:core:hre Running task compile:solidity:solcjs:run +0ms

yarn hardhat clean --global also made no change.

Minimal reproduction steps

n/a

Search terms

No response

@fvictorio
Copy link
Member

@yvasilyev92 can you try upgrading to the latest version of Hardhat?

If that doesn't fix it, then I will need more complete reproduction steps, including which OS and version of node.js you are using. Thanks!

@fvictorio fvictorio added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Jun 29, 2023
@yvasilyev92
Copy link
Author

@fvictorio Thanks for looking into this! I tried upgrading to hardhat ^2.16.1 and that didnt change the behavior.
But after struggling all day I'm close to solving it.

My repo thats having the issue has >100 contracts , I temporarily removed 30 contracts and the yarn hardhat compile command was able to run, it was hanging for a while maybe 10-15 seconds but eventually completed and generated the artifacts . This is the good news.

However I still need those 30 contracts & my project will keep growing. I tried using yarn hardhat compile --concurrency 5 , up to the limit 9 but no luck.

Since I'm assuming its a memory issue causing the compile command to hang and drop how can I increase the amount of memory hardhats compile command uses?

OS: macOS Ventura 13.4.1
Node: node v16.19.0 (npm v8.19.3)

@fvictorio
Copy link
Member

Hmm, that's strange. There are big projects using Hardhat and they don't have this issue. I can take a look if your repo is public (or if it's private but you can give me access).

With respect to increasing the memory, you can do this:

NODE_OPTIONS="--max_old_space_size=16000" npx hardhat compile

@yvasilyev92
Copy link
Author

@fvictorio thanks! Is there a cache hardhat is using for this compilation? (not related to artifact cache)

hardhat:core:hre Running task compile:solidity:log:run-compiler-start +6ms
hardhat:core:hre Running task compile:solidity:solcjs:run +0ms
zsh: bus error NODE_OPTIONS="--max_old_space_size=16000" npx hardhat compile --verbose

@fvictorio
Copy link
Member

The compilation cache is indeed under artifacts. There's also a metadata file under cache/solidity-files-cache.json.

@yvasilyev92
Copy link
Author

yvasilyev92 commented Jun 30, 2023

@fvictorio ah sorry I should've asked is there another local cache or memory space (not the artifacts or cache.solidity-files-cache.json) that hardhat uses when running the compilation command? because I've had 100+ contracts for a while and never had this issue, so I'm wondering if theres anything I can clean out so as to not have to increase memory. My concern is eventually hitting the memory limit again

@fvictorio
Copy link
Member

No, those should be the only ones involved 😕

@yvasilyev92
Copy link
Author

yvasilyev92 commented Jul 3, 2023

Hi @fvictorio , so I tried to increase memory size with NODE_OPTIONS="--max_old_space_size=4096 (also tried increased sizes) and unfortunately that didnt help. I also tried using the hardhat --max-memory flag and that also didnt help.

Rather than deleting 30 contracts I tried deleting just 1 contract and running "yarn hardhat compile --verbose", after which the solcjs:run step lagged for ~10 seconds and spit out a new error. Looks like it even sent a sentry event.

hardhat:core:hre Running task compile:solidity:log:run-compiler-start +4ms
hardhat:core:hre Running task compile:solidity:solcjs:run +0ms
An unexpected error occurred:

RuntimeError: table index is out of bounds
at wasm://wasm/04ebca86:wasm-function[364]:0x292b4
at wasm://wasm/04ebca86:wasm-function[21822]:0x715b0d
at invoke_viiiiii (/Users/$USER/Library/Caches/hardhat-nodejs/compilers-v2/wasm/soljson-v0.8.13+commit.abaa5c0e.js:110:40866)
at wasm://wasm/04ebca86:wasm-function[21824]:0x716162
at invoke_viiiiiiiii (/Users/$USER/Library/Caches/hardhat-nodejs/compilers-v2/wasm/soljson-v0.8.13+commit.abaa5c0e.js:110:44016)
at wasm://wasm/04ebca86:wasm-function[21826]:0x719c29
at invoke_ii (/Users/$USER/Library/Caches/hardhat-nodejs/compilers-v2/wasm/soljson-v0.8.13+commit.abaa5c0e.js:110:39662)
at wasm://wasm/04ebca86:wasm-function[21890]:0x72b720
at invoke_iii (/Users/$USER/Library/Caches/hardhat-nodejs/compilers-v2/wasm/soljson-v0.8.13+commit.abaa5c0e.js:110:40323)
at wasm://wasm/04ebca86:wasm-function[21892]:0x72c146
hardhat:sentry:subprocess starting subprocess +0ms
hardhat:sentry:subprocess sentry event was sent +3ms

@fvictorio Do you know what could cause an issue like this with hardhat compile? Seems to keep dropping off at the solcjs:run step

Btw after reading the verbose logs in the case of a successful run I noticed the step after solcjs:run is log:run-compiler-end

hardhat:core:hre Running task compile:solidity:solcjs:run +1ms
hardhat:core:hre Running task compile:solidity:log:run-compiler-end +2m
hardhat:core:hre Running task compile:solidity:check-errors +247ms
hardhat:core:hre Running task compile:solidity:log:compilation-errors +0ms
hardhat:core:hre Running task compile:solidity:emit-artifacts +0ms

Could the issue lie within that step?

@fvictorio
Copy link
Member

IIRC, the time indicated there is how much time was ellapsed since the last log, so it's the solcjs:run part that is taking 2 minutes.

Which, to be honest, it's not that surprising if you have a lot of contracts (and even less surprising if you are using viaIR) because solcjs is quite slow compared to the native compiler.

What I'm not sure about is why you are getting a solcjs compiler instead of a native one, which is much faster. Which OS are you using?

@clauBv23
Copy link
Contributor

clauBv23 commented Jul 3, 2023

I had a similar issue a couple of months ago and solved it by disabling the Yul optimizer.
In my case, the issue was that had some really huge contracts and looked like the compilation process was taking a lot of time and never ended, and with the Yul optimizer disabled was also taking some time but at least ended.

The same project also had a Heap out of memory issue, but was when testing not compiling.

I was not using solcjs so, might not be the same issue tho. Hope it helps!

@yvasilyev92
Copy link
Author

@clauBv23 thank you! Seems like a very similar issue. So disabling the Yul optimizer helped with the Heap out of memory issue?

@fvictorio I'm on macOS Ventura 13.4.1
I have both solc and solcjs , what kind of configuration can I do to have hardhat use solc & ignore solcjs?

Update: So with 100+ contracts, I cleared out my artifacts + cache, I deleted 5 contracts and was able yarn hardhat compile to run successfully. Then I added those 5 contracts back in and ran hardhat compile again and was able to generate the artifacts for those.

I'm still searching for a solution but I suppose this temporary workaround is this.. so in the case I ever need to recompile the artifacts for all 100+ contracts I just need to delete a few contracts , run yarn hardhat compile, bring back the deleted and run yarn hardhat compile again.

@fvictorio
Copy link
Member

fvictorio commented Jul 6, 2023

what kind of configuration can I do to have hardhat use solc & ignore solcjs?

Hardhat tries to use the native solc first and, if that doesn't work, it switches to solcjs (which is much slower but always works).

Since you already tried hh clean --global and that didn't fix it, then we should figure out why the native solc is not working for you. To do that, find the path to the compiler and run it with the --version flag.

In macOS, you should run something like this:

~/Library/Caches/hardhat-nodejs/compilers-v2/macosx-amd64/solc-macosx-amd64-v0.8.17+commit.8df45f5f --version

(give or take, go down that dir path until you find the compiler that Hardhat downloaded, which in your case seems to be version 0.8.13)

What output do you get?

so in the case I ever need to recompile the artifacts for all 100+ contracts I just need to delete a few contracts , run yarn hardhat compile, bring back the deleted and run yarn hardhat compile again.

That's terrible, let's see if we can find the root cause here 😞

@fvictorio
Copy link
Member

Hey @yvasilyev92, are you still getting this issue?

@thanhnguyen2187
Copy link

thanhnguyen2187 commented Aug 2, 2023

I also encountered this issue, and maybe you should try to... wait for around 10 or 20 minutes? For my case (also compiling a lot of contracts in my company's repository), after around 10 minutes, it works as expected.

@alcuadrado
Copy link
Member

@thanhnguyen2187 that's unexpected. Can you share the output with a run with --verbose? Also, are you using viaIR?

@thanhnguyen2187
Copy link

@alcuadrado for the output log, I also experienced a freeze at this line:

  hardhat:core:tasks:compile Native solc binary doesn't work, using solcjs instead. Try running npx hardhat clean --global +4s
  hardhat:core:hre Running task compile:solidity:log:download-compiler-start +5ms
Downloading compiler 0.8.18
  hardhat:core:solidity:downloader Downloading compiler list for platform wasm +1ms
  hardhat:core:solidity:downloader Downloading compiler 0.8.18+commit.87f61d96 +464ms
  hardhat:core:solidity:downloader Checking native solc binary +785ms
  hardhat:core:hre Running task compile:solidity:log:download-compiler-end +1s
  hardhat:core:hre Running task compile:solidity:log:run-compiler-start +0ms
  hardhat:core:hre Running task compile:solidity:solc:run +1ms
  hardhat:core:hre Running task compile:solidity:log:run-compiler-end +51ms
  hardhat:core:hre Running task compile:solidity:check-errors +9ms
  hardhat:core:hre Running task compile:solidity:log:compilation-errors +0ms
  hardhat:core:hre Running compile:solidity:log:compilation-errors's super +1ms
  hardhat:core:hre Running task compile:solidity:emit-artifacts +0ms
  hardhat:core:tasks:compile Emitting artifact for contract 'WETH' +1s
  hardhat:core:hre Running task compile:solidity:get-artifact-from-compilation-output +3ms
  hardhat:core:hre Running task compile:solidity:log:download-compiler-end +2s
  hardhat:core:hre Running task compile:solidity:log:run-compiler-start +1ms
  hardhat:core:hre Running task compile:solidity:solcjs:run +0ms

In the end, it doesn't have any problem:

  hardhat:core:hre Running task compile:solidity:get-artifact-from-compilation-output +0ms
  hardhat:core:hre Running task typechain:generate-types +58ms
Generating typings for: 166 artifacts in dir: ./build/typechain/ for target: ethers-v5
Successfully generated 426 typings!
  hardhat:core:hre Running task compile:solidity:log:compilation-result +7s
Compiled 154 Solidity files successfully
  hardhat:core:hre Running task compile:remove-obsolete-artifacts +0ms
  hardhat:core:cli Killing Hardhat after successfully running task compile +0ms

Not sure what do you mean by viaIR, but I invoked npx hardhat compile directly.

@fvictorio
Copy link
Member

@thanhnguyen2187 can you share your Hardhat config?

@fvictorio
Copy link
Member

I'm going to tentatively close this for book-keeping reasons (we don't have enough information to look into it, and it's been some weeks since we asked), but I will happily re-open it if someone can provide more info.

@fvictorio fvictorio closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
@github-project-automation github-project-automation bot moved this to Done in Hardhat Aug 23, 2023
@yvasilyev92
Copy link
Author

Hi @fvictorio , apologies for not responding. I'm still having this issue, same as @thanhnguyen2187 .
I really do suspect its a memory issue because the compile only works once I delete enough contracts , looks like right now it works once I get down to 266 artifacts.

Generating typings for: 266 artifacts in dir: ../src/generated/contract-types for target: ethers-v5
Successfully generated 401 typings!
Compiled 225 Solidity files successfully

Anything greater than 266 will not work.
I'm running on a MacBook Pro M1 Max , 32 GB

I really think the solution for this would be to find where in local storage Hardhat uses and to wipe that completely because I didn't always have this issue. Seems like over time the allowed memory allocation for HH compile became smaller and smaller and this is the cause of the issue.

@fvictorio
Copy link
Member

fvictorio commented Sep 11, 2023

@yvasilyev92 is your project public? These issues are hard to investigate without some way to reproduce them.

@yvasilyev92
Copy link
Author

@fvictorio no unfortunately its not public. Its private and the other members have no issue in compiling. Could you help me determine where in local storage hardhat stores any bin files / related files. I want to completely wipe all files hardhat is storing.

@fvictorio
Copy link
Member

Hey, sorry for not responding sooner. npx hardhat clean --global should remove the global cache.

@yvasilyev92
Copy link
Author

Thanks @fvictorio , I was using yarn hardhat compile but after switching to npx I'm getting a new log:
zsh : bus error npx hardhat compile
Always after the
hardhat:core:hre Running task compile:solidity:solcjs:run +0ms

@yvasilyev92
Copy link
Author

yvasilyev92 commented Sep 29, 2023

@fvictorio some additional testing i've been doing.
On a macbook pro where I can run npx hardhat compile with a test directory where I created around 400 solidity contracts I have these npx hardhat compile --verbose logs as a success.

hardhat:core:hre Running task compile:solidity:handle-compilation-jobs-failures +8ms
hardhat:core:hre Running task compile:solidity:filter-compilation-jobs +0ms
hardhat:core:tasks:compile '0' jobs were filtered out +80ms
hardhat:core:hre Running task compile:solidity:merge-compilation-jobs +12ms
hardhat:core:hre Running task compile:solidity:compile-jobs +33ms
hardhat:core:hre Running compile:solidity:compile-jobs's super +0ms
hardhat:core:tasks:compile Compiling 1 jobs +34ms
hardhat:core:hre Running task compile:solidity:compile-job +3ms
hardhat:core:tasks:compile Compiling job with version '0.8.13' +2ms
hardhat:core:hre Running task compile:solidity:get-compiler-input +0ms
hardhat:core:hre Running compile:solidity:get-compiler-input's super +0ms
hardhat:core:hre Running task compile:solidity:compile +11ms
hardhat:core:hre Running task compile:solidity:solc:compile +0ms
hardhat:core:hre Running task compile:solidity:solc:get-build +0ms
hardhat:core:hre Running task compile:solidity:log:download-compiler-start +2ms
Downloading compiler 0.8.13
hardhat:core:solidity:downloader Downloading compiler 0.8.13+commit.abaa5c0e +0ms
hardhat:core:solidity:downloader Checking native solc binary +4s
hardhat:core:hre Running task compile:solidity:log:download-compiler-end +5s
hardhat:core:hre Running task compile:solidity:log:run-compiler-start +4ms
hardhat:core:hre Running task compile:solidity:solc:run +1ms
hardhat:core:hre Running task compile:solidity:log:run-compiler-end +7s
hardhat:core:hre Running task compile:solidity:check-errors +13ms
hardhat:core:hre Running task compile:solidity:log:compilation-errors +0ms
hardhat:core:hre Running compile:solidity:log:compilation-errors's super +0ms
hardhat:core:hre Running task compile:solidity:emit-artifacts +0ms

And on the macbook pro where I keep getting a failed npx hardhat compile with ~300 contracts I get these unsuccessful logs

hardhat:core:hre Running task compile:solidity:handle-compilation-jobs-failures +6ms
hardhat:core:hre Running task compile:solidity:filter-compilation-jobs +0ms
hardhat:core:tasks:compile force flag enabled, not filtering +163ms
hardhat:core:hre Running task compile:solidity:merge-compilation-jobs +0ms
hardhat:core:hre Running task compile:solidity:compile-jobs +18ms
hardhat:core:hre Running compile:solidity:compile-jobs's super +0ms
hardhat:core:tasks:compile Compiling 1 jobs +19ms
hardhat:core:hre Running task compile:solidity:compile-job +2ms
hardhat:core:tasks:compile Compiling job with version '0.8.13' +1ms
hardhat:core:hre Running task compile:solidity:get-compiler-input +0ms
hardhat:core:hre Running compile:solidity:get-compiler-input's super +0ms
hardhat:core:hre Running task compile:solidity:compile +1ms
hardhat:core:hre Running compile:solidity:compile's super +0ms
hardhat:core:hre Running task compile:solidity:solc:compile +0ms
hardhat:core:hre Running task compile:solidity:solc:get-build +0ms
hardhat:core:tasks:compile Native solc binary doesn't work, using solcjs instead. Try running npx hardhat clean --global +8ms
hardhat:core:hre Running task compile:solidity:log:run-compiler-start +9ms
hardhat:core:hre Running task compile:solidity:solcjs:run +0ms

@yvasilyev92
Copy link
Author

@fvictorio I was somewhat able to fix the issue. Inside my hardhat.config.ts file I upgraded my solidity.compilers.version from 0.8.13 to 0.8.14
My concern this is a temporary solution as the 0.8.14 cached files will eventually start having the same memory issue as the 0.8.13 ones did and this issue will return. Afterall this problem started out of the blue and I was able to compile with 0.8.13 for months before the issue started

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Archived in project
Development

No branches or pull requests

5 participants