dropbox-sdk-js icon indicating copy to clipboard operation
dropbox-sdk-js copied to clipboard

res.buffer is not a function in bun

Open aviadbd opened this issue 1 year ago • 2 comments

Describe the bug I am migrating my web app to bun, and it seems the dropbox SDK usage fails to download files.

To Reproduce

  1. Download bun. I'm using 1.0.30.
  2. Install Dropbox SDK JS - bun install --save-dev dropbox
  3. 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)
})
  1. 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.

aviadbd avatar Mar 30 '24 15:03 aviadbd

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) :

  1. Install node-fetch: bun install --save-dev node-fetch
  2. 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.

aviadbd avatar Mar 30 '24 18:03 aviadbd

Thanks for the detailed report! I'll ask the team to look into addressing this.

greg-db avatar Apr 01 '24 18:04 greg-db