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

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

我想使用airbnb的eslint修改我的代码结构。我已遵循 eslint-config-airbnb 中给出的这些说明。命令启动后 npm run lint,结果包括 'fetch' is not defined 以及 'localStorage' is not defined

我已经完成了这个 github issue,但仍然显示相同的错误 'fetch is not defined'。有没有解决办法。

您可以使用 globals 配置您的 .eslintrc 文件。

将此添加到您的 .eslintrc 文件中。

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

您可以尝试通过 window 对象访问 fetchlocalStorage

window.fetchwindow.localStorage

无需将其添加为例外,只需将其添加到您的 .eslintrc 中,eslint 就会知道它是什么:

  "env": {
    "browser": true
  }