• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

1K
Views
error 'document' is not defined : eslint / React

I'm building a React app, with create-react-app.

I got the following error when running ESLint:
8:3 error 'document' is not defined no-undef.

My app runs without error, but I got this ESLint error in 2 files. See one of those .jsx files and my ESLint configuration.

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
  }
};

How can I fix this ? For the moment I will simply ignore both files ... but I'd rather find a long term solution.

about 3 years ago · Santiago Trujillo
3 answers
Answer question

0

Add "browser": true your env to include global variables (like document, window, etc.)

See the ESLint environment documentation for more information.

about 3 years ago · Santiago Trujillo Report

0

set an env property in you eslint.rc file, e.g.

{
    "env": {
        "browser": true,
        "node": true
    }
}
about 3 years ago · Santiago Trujillo Report

0

In your package.json, specify the test environment for jest as "jsdom" as follows:

  "jest": {
    "testEnvironment": "jsdom"
  }

I faced the same issue and it worked well for me.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error