-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError: globalThis is not defined #2795
Comments
Thanks for finding this! This will probably work in Node.js v13, but we mean to support v10, so this is a bug. We'll try to get it fixed ASAP. |
It looks like Thanks for the quick reply 😃 |
BTW, I generated and compared different |
Facing same bug here. |
Hi @domenic , still getting this error.
evalmachine.<anonymous>:1
globalThis
^
ReferenceError: globalThis is not defined
at evalmachine.<anonymous>:1:1
at setupWindow (../../node_modules/jsdom/lib/jsdom/browser/Window.js:51:55)
at new Window (../../node_modules/jsdom/lib/jsdom/browser/Window.js:107:3)
at exports.createWindow (../../node_modules/jsdom/lib/jsdom/browser/Window.js:38:10)
at new JSDOM (../../node_modules/jsdom/lib/api.js:36:20) Any ideas? |
You'll need to post a new issue similar to the one in the OP, including the minimal reproduction case (not involving other technology like Jest). |
FWIW, this reproduces the issue: // polyfill globalThis for older nodes
globalThis = global;
const { JSDOM } = require('jsdom');
new JSDOM('', {runScripts: 'dangerously'}); Setting Not sure it's necessarily something that needs to be fixed/changed in JSDOM, but it might be made more robust*? Anyways, hopes this helps folks hitting this issue to track it down. It's not Jest itself that does this. *) e.g. filtering on |
@clarkdo |
hi, where(what file) did you define this line :
|
@pawellesniowski you can include a js file, and define this line in the js file. |
globalthis/polyfill from https://github.com/es-shims/globalThis resolve problem for me |
my way.... global.globalThis=global; .... |
The solution for me is to use this library https://www.npmjs.com/package/jest-environment-jsdom which creates a jest jsdom environment with the version jsdom from any jest version. For example, by using jest-environment-jsdom version 25, you will use the jsdom from this version. And in jest 25, the jsdom version was still compatible with node 10
// jest config
displayName: 'dom',
testEnvironment: 'jest-environment-jsdom', |
@caihaibin1991 suggestion work for me thanks! |
I updated the node version from v11.15.0 to LTS (v15.11.0, npm v7.6.0), and then it works. |
You can use |
Where? |
I don't actually remember the use case in which I used it |
I tried |
Basic info:
Minimal reproduction case
Then you'll see the error, since Node.js doesn't support globalThis but
js-globals.json
includesglobalThis
andrunInContext('globalThis', windowInstance)
is executed in https://github.com/jsdom/jsdom/blob/master/lib/jsdom/browser/Window.js#L48The text was updated successfully, but these errors were encountered: