ReferenceError: fetch is not defined

前端 未结 10 1838
闹比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:26

    The fetch API is not implemented in Node.

    You need to use an external module for that, like node-fetch.

    Install it in your Node application like this

    npm i node-fetch --save
    

    then put the line below at the top of the files where you are using the fetch API:

    const fetch = require("node-fetch");
    

提交回复
热议问题