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.
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.
Add "browser": true
your env
to include global variables (like document, window, etc.)
See the ESLint environment documentation for more information.
If you have .eslintrc.json
file then add following code snippet.
{
...otherSettings,
"env": {
"browser": true,
"node": true
}
}
if you do not have .eslintrc.json
then you can add these settings in you package.json
file.
{
...otherSettings,
"eslintConfig": {
"globals": {
"window": true
}
}
}
set an env property in you eslint.rc file, e.g.
{
"env": {
"browser": true,
"node": true
}
}