dropbox-sdk-js
dropbox-sdk-js copied to clipboard
res.buffer is not a function in bun
Describe the bug I am migrating my web app to bun, and it seems the dropbox SDK usage fails to download files.
To Reproduce
- Download bun. I'm using 1.0.30.
- Install Dropbox SDK JS -
bun install --save-dev dropbox - Using this code:
// dropbox.ts
const dropbox = new Dropbox({accessToken: process.env.DROPBOX_ACCESS_TOKEN, fetch: fetch});
const result = await dropbox.filesListFolder({path: "/products", recursive: true})
dropbox.filesDownload({path: "/path/to/file.jpg"}).then(
{result} => {
console.debug(result.name)
}
).catch(err => {
console.error(err)
})
- Run it using
bun dropbox.ts
Expected Behavior I expect it to run, and print the name of my file. The file exists in the path, and is accessible to the app (the node JS app finds it and has access to it; moreover, if I use a non-existent file, I get a 409 error, and I don't in this case).
Actual Behavior I get an error, like this:
62 | if ((0, _utils.isWindowOrWorker)()) {
63 | res.blob().then(function (data) {
64 | return resolve(data);
65 | });
66 | } else {
67 | res.buffer().then(function (data) {
^
TypeError: res.buffer is not a function. (In 'res.buffer()', 'res.buffer' is undefined)
at /project/node_modules/dropbox/cjs/src/response.js:67:7
at new Promise (:1:21)
at parseDownloadResponse (/project/node_modules/dropbox/cjs/src/response.js:61:10)
at /project/node_modules/dropbox/cjs/src/dropbox.js:146:20
Screenshots N/A
Versions
- What version of the SDK are you using? 10.34.0
- What version of the language are you using? Whatever Bun's using
- Are you using Javascript or Typescript? TypeScript
- What platform are you using? (if applicable) Bun 1.0.30
Additional context None.
I think I've figured it out. It seems that Bun's fetch has a different API than node-fetch; However, it still seems to make sense to fix this problem, so I hope it'll remain open.
To locally fix it (for me it worked at least) :
- Install node-fetch:
bun install --save-dev node-fetch - Use node-fetch instead of Bun's fetch, meaning add an
import fetch from "node-fetch", which should sort it out for the example I offered in the original post.
Thanks for the detailed report! I'll ask the team to look into addressing this.