NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

Home Page:https://hardhat.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`hardhat compile` randomly and quietly stops before compiling contracts

sebastiendan opened this issue · comments

Edit by @fvictorio: Hardhat 2.16.1 should this problem.


Version of Hardhat

2.14.0

What happened?

npx hardhat compile sometimes goes on with compiling contracts and sometimes (seems totally random) silently stops at the Downloading compiler ... step before any contracts are actually compiled. This issue is reproducible with no contracts already compiled and in docker.

Minimal reproduction steps

Here's a simple repository where you can observe the problem: repo.

This CI workflow run shows in the logs that the compilation didn't happen: log.

In addition, one can run the docker container in interactive mode and manually run the build command to see that, again, the command sometimes doesn't build nor throws an error but simply quietly stops without compiling (same output as the CI log above):

  • Run the container in interactive mode: docker run --rm -it ghcr.io/sebastiendan/hardhat-compile-issue:main bash
  • Run the compile command: npm run build
  • Observe sometimes an actual compilation, sometimes a quiet stop in the command execution
    (run the above multiple times by exiting the container and re-running the two commands above)

Search terms

no compilation

See:

This is due to a regression in the latest node versions 18 and 20. Somewhere after "Downloading compiler list for platform" when trying to a compiler, it failed to download it and failed silently.

Try to use a node version other than the latest. I'm surprised the node team hasn't done a release yet since this is a widespread issue.

@fuxingloh thanks for pointing that out, I tried node 18.12.1 and the issue disappeared!

@fuxingloh I can confirm it works with the 18.15.0-slim docker tag of node 👍

Wow, this is so weird. Thanks everyone for the info.

I still don't quite understand why and when this happens, but it's good to know that changing the version of node fixes the issue.

@sebastiendan I'm going to edit your issue so this information shows up first for people landing here.

FWIW, Github actions is currently using 18.16.0 in Ubuntu 20 / 22 (latest) if the Node version is specified just as 18: actions/runner-images@af6dd20.

Specifying a different minor version (e.g node-version: 18.15) indeed solves the problem.

I'm getting this error (more or less, I think?), also reported in #2569

Here's the Github Actions run: https://github.com/streamr-dev/network-contracts/actions/runs/5088395393/jobs/9144745279?pr=523#step:6:15

Explanation:

  • rm -rf artifacts && hardhat compile && rm -rf dist && tsc -p tsconfig.build.json
    • I try to force compilation by deleting artifacts first (to make double sure there isn't an existing artifacts directory, so hardhat might skip compilation)
    • after, I delete dist just in case, and run tsc that outputs to dist
  • src/exports.ts(1,66): error TS2307: Cannot find module '../artifacts/contracts/OperatorTokenomics/Operator.sol/Operator.json' or its corresponding type declarations
    • tsc says: nothing found in artifacts. Right after hardhat compile.

What makes this problem frustrating is that

  • it doesn't happen every time in Github Actions
  • it doesn't happen much if at all locally

EDIT: This happens when running on Node 18.16.0

Indeed, downgrading to Node 18.12.1 as suggested by @stefiix92 fixed it. Seems consistent with the theory that some compilers (different solidity versions) don't get downloaded and run at all. Difference in logs with the working run was that the broken run (linked above) doesn't generate warnings; it logs Downloading compiler 0.8.13 then just exits with 0. It probably should throw error and exit with 1.

I was able to add a few more logging statements through the compile task and reproduce the issue. It looks like response streaming occasionally stops while downloading the compiler list or the compiler itself.

There is an issue about stream.pipeline ending prematurely filed in the Node repo. The code to reproduce the issue is very similar to what hardhat in the download function, so I assume the Node bug is the cause here. A fix (nodejs/node#48435) is on the way.

We are still affected by this issue, is Node.JS going to fix that?

Honestly, I thought they were going to release a fix sooner. I'll see if there's some workaround we can implement on our side.

Hi everyone, we just released Hardaht v2.16.1 which should fix this problem.