From 88b187752281cf504ec13464d5d1444a32ee7ff4 Mon Sep 17 00:00:00 2001 From: Victor Repkow Date: Wed, 17 May 2023 11:19:22 -0400 Subject: [PATCH] fix(api): add duplex configuration to fetch (#19) Node sneakily introduced a change to the fetch API that now requires that the `duplex` option be set on all requests with contain a payload body: https://github.com/nodejs/node/issues/46221 , which means that the CLI now fails on node >18.13, >19.1, 20, and running the CLI on those versions will cause the following exception: ``` RequestInit: duplex option is required when sending a body. Exited with code exit status 1 ``` This configures all fetch requests with bodies to set the duplex option to the only value that is allowed by the spec for now, which is `"half"`. This should have no impact on older node versions since it's the only option available, but will allow the CLI to run on those newer versions without throwing an error. --- src/apiClient.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/apiClient.js b/src/apiClient.js index a8cde16..d07c326 100644 --- a/src/apiClient.js +++ b/src/apiClient.js @@ -52,6 +52,7 @@ class ApiClient { method: 'POST', headers: this.headers, body: JSON.stringify(data), + duplex: 'half', }); } @@ -110,6 +111,7 @@ class ApiClient { maxRetryDelay, method: 'PUT', body: contents, + duplex: 'half', }); if (this._gcsBucket) { @@ -123,6 +125,7 @@ class ApiClient { name: fileData.name, bucket: this._gcsBucket, }), + duplex: 'half', }); }