matthew-andrews / isomorphic-fetch

Isomorphic WHATWG Fetch API, for Node & Browserify
MIT License
6.95k stars 289 forks source link

isomorphic-fetch & typescript - is the dom polyfill required to run on nodeJs? #167

Open JakeSummers opened 6 years ago

JakeSummers commented 6 years ago

Good Evening,

I am attempting to use iosmorphic-fetch on node 6.10 with typescript but am running into some issues. I am trying to remove the dom lib/polyfill from my tsconfig:

  "compilerOptions": {
    "target": "es2015", 
    "module": "commonjs",
    "lib": [
        "esnext",
       "dom"   // <-- would like to remove this
    ],

When I try to do this, I get the following error during my tsc (typescript compiler):

node_modules/@types/isomorphic-fetch/index.d.ts(8,30): error TS2552: Cannot find name 'fetch'. Did you mean '_fetch'?

Not sure if I have botched the setup somehow or whether this is a bug.

Package.json:

    "dependencies": {
        "es6-promise": "^4.2.4",
        "isomorphic-fetch": "^2.2.1",
        "node-fetch": "^2.1.1",
    },
    "devDependencies": {
        "@types/isomorphic-fetch": "0.0.34",

Thanks!

smonusbonus commented 6 years ago

Would assume this is because a global fetch method is only available in a browser environment, not in node.js. So you probably have to declare it manually, like so declare const fetch: any;