I am publishing a react ponent to npm package, I added Webpack, babel, linting, and test to it, initially Webpack builds successfully, tests were running successfully, but then I added linting and remove node_modules folder and then install again using npm install to verify everything, at this point test breaks, Initially I got jest not found error which I fixed by npm install jest, after that, got " ReferenceError: it is not defined", fixed by import { describe, expect, it } from "@jest/globals";, now getting " ReferenceError: document is not defined", tried multiple solutions like setting the "testEnvironment": "jsdom", tried to set global.document, but nothing is working, you can see the plete code at
I am publishing a react ponent to npm package, I added Webpack, babel, linting, and test to it, initially Webpack builds successfully, tests were running successfully, but then I added linting and remove node_modules folder and then install again using npm install to verify everything, at this point test breaks, Initially I got jest not found error which I fixed by npm install jest, after that, got " ReferenceError: it is not defined", fixed by import { describe, expect, it } from "@jest/globals";, now getting " ReferenceError: document is not defined", tried multiple solutions like setting the "testEnvironment": "jsdom", tried to set global.document, but nothing is working, you can see the plete code at
https://github./asifsha/react-picker-cascader
Share Improve this question edited Jun 19, 2020 at 13:55 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Jun 18, 2020 at 19:33 AsifAsif 732 silver badges8 bronze badges 3-
Just in case, is
jsdom
still in your modules ? – aquinq Commented Jun 19, 2020 at 13:40 - Yes, I also install npm install jsdom, but getting same error – Asif Commented Jun 19, 2020 at 17:30
-
Hi @Asif, did you manage to fix it for [email protected]? I am facing same problem. Global variables are not exposed independently;
global.describe
andglobal.document
are present, howeverdescribe
anddocument
are not. – Ovais Commented Jun 29, 2020 at 8:17
1 Answer
Reset to default 4In my case node upgrade did the trick. I was using node v10.13.0 and upgraded to v10.16.0. It seems that minimum version required is v10.14.2 (at least for npm package babel-jest v26.1.0)