小编典典

错误“文档”未定义:eslint / React

reactjs

我正在使用create-react-app构建一个React应用程序。

运行ESLint时出现以下错误:
8:3 error 'document' is not defined no-undef.

我的应用程序运行没有错误,但是我在2个文件中遇到了这个ESLint错误。请参阅这些.jsx文件之一和我的ESLint配置。

index.jsx:

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';

ReactDOM.render(
  <App />,
  document.getElementById('root'),
);

eslintrc.js:

module.exports = {
  "extends": "airbnb",
  "plugins": [
      "react",
      "jsx-a11y",
      "import"
  ],
  "env": {
    "jest": true
  }
};

我怎样才能解决这个问题 ?目前,我将只忽略这两个文件……但我希望找到一个长期解决方案。


阅读 380

收藏
2020-07-22

共1个答案

小编典典

添加"browser": true您的env包括全局变量(如文件,窗口等)

有关更多信息,请参见ESLint环境文档

2020-07-22