Skip to content

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

Description

@KleaTech

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

Activity

  1. KleaTech commented on Mar 30, 2023

    @KleaTech
    Author

    Possibly related to #42962

  2. bnoordhuis commented on Apr 5, 2023

    @bnoordhuis
    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.

  3. KleaTech commented on Apr 5, 2023

    @KleaTech
    Author

    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.

  4. targos commented on Apr 5, 2023

    @targos
    Member

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

  5. KleaTech commented on Apr 5, 2023

    @KleaTech
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions