Skip to content

Commit

Permalink
fix(api): add duplex configuration to fetch
Browse files Browse the repository at this point in the history
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: nodejs/node#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.
  • Loading branch information
vicrep authored Apr 28, 2023
1 parent 78639d5 commit 97cde1d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/apiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ApiClient {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data),
duplex: 'half',
});
}

Expand Down Expand Up @@ -110,6 +111,7 @@ class ApiClient {
maxRetryDelay,
method: 'PUT',
body: contents,
duplex: 'half',
});

if (this._gcsBucket) {
Expand All @@ -123,6 +125,7 @@ class ApiClient {
name: fileData.name,
bucket: this._gcsBucket,
}),
duplex: 'half',
});
}

Expand Down

0 comments on commit 97cde1d

Please sign in to comment.