dropbox-sdk-js
dropbox-sdk-js copied to clipboard
this.fetch is not a function error received
The bug occurs upon calling a next.js api which uses the filesUpload() or filesCreateFolderV2() function. It will automatically close the request returning this.fetch is not a function error.
Regarding when the error occurs during the api call, it seems to occur within the instance/import itself since it is the only thing logged during the request which means it did not proceed into the middlewares/services.
The bug seems to only occur on the deployed application. It cannot be replicated in local. We also have updated the environment variables (Client Secret, Refresh Token, Access Token) but to no avail.
Dropbox Instance:
import { Dropbox } from 'dropbox';
const dbx = new Dropbox({
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
clientId: process.env.DROPBOX_CLIENT_ID,
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
});
Screenshots:
Versions
- What version of the SDK are you using? 10.34.0
- What version of the language are you using? Node 18.x.0 , Next.js 14.0.4
- Are you using Javascript or Typescript? Javascript
- What platform are you using? (if applicable) Vercel
The Dropbox JavaScript SDK uses this.fetch to perform the network requests to the Dropbox API servers for the Dropbox API calls. In a Node environment, that is supposed to get set from node-fetch. Is there some reason that may not be working (for instance, is node-fetch not properly installed?) or may be overwritten by something else in your deployed application?
It maybe overwritten by something else but not sure. In the meantime, I explicitly imported fetch and passed it to the dropbox instance. Works
import { Dropbox } from 'dropbox';
import fetch from 'fetch';
const dbx = new Dropbox({
refreshToken: process.env.DROPBOX_REFRESH_TOKEN,
clientId: process.env.DROPBOX_CLIENT_ID,
clientSecret: process.env.DROPBOX_CLIENT_SECRET,
fetch
});
Thanks for following up. I'm glad to hear you got this working.
It sounds like this is related to something in that particular environment, but if you find there's something in the Dropbox SDK itself that needs to be addressed, please let us know so we can look into it.