Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

res.buffer is not a function in bun #1135

Open
aviadbd opened this issue Mar 30, 2024 · 2 comments
Open

res.buffer is not a function in bun #1135

aviadbd opened this issue Mar 30, 2024 · 2 comments
Labels

Comments

@aviadbd
Copy link

aviadbd commented Mar 30, 2024

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 aviadbd added the bug label Mar 30, 2024
@aviadbd
Copy link
Author

aviadbd commented Mar 30, 2024

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.

@greg-db
Copy link
Contributor

greg-db commented Apr 1, 2024

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

@decovicdev decovicdev mentioned this issue Apr 23, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants