ReferenceError: fetch is not defined

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

    For those also using typescript on node-js and are getting a ReferenceError: fetch is not defined error

    npm install these packages:

        "amazon-cognito-identity-js": "3.0.11"
        "node-fetch": "^2.3.0"
    

    Then include:

    import Global = NodeJS.Global;
    export interface GlobalWithCognitoFix extends Global {
        fetch: any
    }
    declare const global: GlobalWithCognitoFix;
    global.fetch = require('node-fetch');
    

提交回复
热议问题