Skip to content

Commit 2f59cec

Browse files
committed
fix: node 18 compat issue in the node fetch client
1 parent d66f818 commit 2f59cec

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"files.insertFinalNewline": false,
1111

1212
"search.exclude": {
13-
"coverage": true,
13+
"coverage": true
1414
}
1515
}

src/targets/node/fetch/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ export const fetch: Client = {
7373

7474
if (param.fileName) {
7575
includeFS = true;
76-
push(`formData.append('${param.name}', await fs.openAsBlob('${param.fileName}'));`);
76+
77+
// Whenever we drop support for Node 18 we can change this blob work to use
78+
// `fs.openAsBlob('filename')`.
79+
push(
80+
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`,
81+
);
7782
}
7883
});
7984

src/targets/node/fetch/fixtures/multipart-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22

33
const formData = new FormData();
4-
formData.append('foo', await fs.openAsBlob('src/fixtures/files/hello.txt'));
4+
formData.append('foo', await new Response(fs.createReadStream('src/fixtures/files/hello.txt')).blob());
55
formData.append('bar', 'Bonjour le monde');
66

77
const url = 'https://httpbin.org/anything';

src/targets/node/fetch/fixtures/multipart-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs';
22

33
const formData = new FormData();
4-
formData.append('foo', await fs.openAsBlob('src/fixtures/files/hello.txt'));
4+
formData.append('foo', await new Response(fs.createReadStream('src/fixtures/files/hello.txt')).blob());
55

66
const url = 'https://httpbin.org/anything';
77
const options = {method: 'POST', body: formData};

0 commit comments

Comments
 (0)