diff --git a/.changeset/tricky-parents-warn.md b/.changeset/tricky-parents-warn.md new file mode 100644 index 0000000000..85c908f339 --- /dev/null +++ b/.changeset/tricky-parents-warn.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Fixed an issue related to compiler downloads in node v18.16.x diff --git a/packages/hardhat-core/src/internal/util/download.ts b/packages/hardhat-core/src/internal/util/download.ts index 7151b71606..eb5b5811cc 100644 --- a/packages/hardhat-core/src/internal/util/download.ts +++ b/packages/hardhat-core/src/internal/util/download.ts @@ -1,9 +1,7 @@ import type { Dispatcher } from "undici"; -import fs from "fs"; import fsExtra from "fs-extra"; import path from "path"; -import util from "util"; import { getHardhatVersion } from "./packageInfo"; import { shouldUseProxy } from "./proxy"; @@ -26,9 +24,7 @@ export async function download( timeoutMillis = 10000, extraHeaders: { [name: string]: string } = {} ) { - const { pipeline } = await import("stream"); const { getGlobalDispatcher, ProxyAgent, request } = await import("undici"); - const streamPipeline = util.promisify(pipeline); let dispatcher: Dispatcher; if (process.env.http_proxy !== undefined && shouldUseProxy(url)) { @@ -52,10 +48,11 @@ export async function download( }); if (response.statusCode >= 200 && response.statusCode <= 299) { + const responseBody = await response.body.arrayBuffer(); const tmpFilePath = resolveTempFileName(filePath); await fsExtra.ensureDir(path.dirname(filePath)); - await streamPipeline(response.body, fs.createWriteStream(tmpFilePath)); + await fsExtra.writeFile(tmpFilePath, responseBody); return fsExtra.move(tmpFilePath, filePath, { overwrite: true }); } // undici's response bodies must always be consumed to prevent leaks