简体   繁体   中英

“fetch” is undefined and “localStorage” is undefined , on using eslint-config-airbnb in react.js

I want to modify my code structure using eslint of airbnb. I have follwed these instruction given in eslint-config-airbnb . After initiating the command npm run lint , results consists of 'fetch' is not defined and also, 'localStorage' is not defined .

I have gone through this github issue , but still error is shown as the same 'fetch is not defined' . Is there any solutions for it.

You can configure your .eslintrc file with globals .

Add this to your .eslintrc file.

"globals": {
        "localStorage": true,
        "fetch": true
    }

No need to add it as an exception, just add this to your .eslintrc and eslint will know what it is:

  "env": {
    "browser": true
  }

you can try to access to the fetch and localStorage through window object.

window.fetch , window.localStorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM