ReferenceError: fetch is not defined

前端 未结 10 1848
闹比i
闹比i 2020-11-29 17:48

I have this error when I compile my code in node.js, how can I fix it?

RefernceError: fetch is not defined

This is the function I am doing, it is re

10条回答
  •  温柔的废话
    2020-11-29 18:15

    The following works for me in Node.js 12.x:

    npm i node-fetch;
    

    to initialize the Dropbox instance:

    var Dropbox = require("dropbox").Dropbox;
    var dbx = new Dropbox({
       accessToken: ,
       fetch: require("node-fetch")    
    });
    

    to e.g. upload a content (an asynchronous method used in this case):

    await dbx.filesUpload({
      contents: ,
      path: 
    });
    

提交回复
热议问题