Skip to content
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

Cannot redefine property: window (>=v19.7.0) #47310

Closed
KleaTech opened this issue Mar 30, 2023 · 5 comments
Closed

Cannot redefine property: window (>=v19.7.0) #47310

KleaTech opened this issue Mar 30, 2023 · 5 comments

Comments

@KleaTech
Copy link

KleaTech commented Mar 30, 2023

Version

v19.7.0

Platform

Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
global.window = jsdom.window as any;

How often does it reproduce? Is there a required condition?

Error is consistent. Was introduced in v19.7.0. Not reproducible on v19.6.1 and below.

What is the expected behavior? Why is that the expected behavior?

Should work same as in v19.6.1 and before. No error.

What do you see instead?

TypeError: Cannot redefine property: window

Additional information

No response

@KleaTech
Copy link
Author

Possibly related to #42962

@bnoordhuis
Copy link
Member

Do you have a test case using only the vm module? Your bug report is unlikely to get attention if it depends on a big third-party module like jsdom.

@KleaTech
Copy link
Author

KleaTech commented Apr 5, 2023

Since I'm not familiar with the inner workings of jsdom I cannot remove that as a dependency. All I can do is provide simple exact repro steps:

  • Save below snippet as test.js.
  • Run npm i jest jest-environment-jsdom
  • Run npx jest
/**
 * @jest-environment jsdom
 */
"use strict"
global.window = {};

Since the issue is reproducible with the snippet above on node version 19.7.0 but not on 19.6.1 I think there have been a breaking change somewhere between these two versions in node.

@targos
Copy link
Member

targos commented Apr 5, 2023

This was possibly fixed by aa6e9c8
Can you try with the latest nigthly?

@KleaTech
Copy link
Author

KleaTech commented Apr 5, 2023

Works fine with latest nightly.
I also tested with a nightly before the mentioned commit (from March 17) and there it's failing. But on v20.0.0-nightly20230405f6f3e22016 it's passed.
Awesome, thank you very much.
I'm closing the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants