eslint: "fetch" is not defined

import 'isomorphic-fetch';

expose a function called “fetch” as so react-native projects.

which rule i need to use to suppress this error just for this case?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 5
  • Comments: 27 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Set the environment for a browser inside the .eslintrc file:

env:
  browser: true

Skip down a line in the docs, how about "globals": { "fetch": false }?

Just adding to @julius-mfc, the following will work in a non-yaml fashion:

"env": {
    "browser": true
  }

fetch is a global though, isn’t it? https://developer.mozilla.org/en/docs/Web/API/Fetch_API

isomorphic-fetch is just a polyfill, IIRC. Whether fetch should be a predefined global I don’t know, but it’s not a react specific feature at all, unless I’ve misunderstood something

it might be preferable to use

/* global fetch:false */

at the top of your file

or

"globals": {
  "fetch": false
}

in your config, so as not to pull in other globals from the browser env.

(the false stops you from being allowed to overwrite it)

I think this would be an excellent discussion to have in the eslint-plugin-react and/or react-native repositories. 😉

So really React Native, which does provide fetch, should also provide a plugin or at least document the ‘integration’. 😃

For RN you could also go for something like https://github.com/satya164/eslint-plugin-react-native-globals or potentially open up at issue at https://github.com/sindresorhus/globals so you could do {"env": "react-native": true}.