Repository navigation
"TypeError: Cannot redefine property: window" (v18.6.0) #47563
Description
Activity
That bug was fixed by #46615 but it hasn't been back-ported to v18.x yet. That happens automatically after some time so it'll likely show up in a release in the next few weeks. You can follow the linked pull request to get notified.
Reacted by Yehuda Schwartz- added a commit that references this issue
on Apr 20, 2023 - added a commit that references this issue
on Apr 25, 2023 - added a commit that references this issue
on Apr 25, 2023 - added 2 commits that reference this issue
on Apr 26, 2023 - added a commit that references this issue
on Apr 27, 2023 That bug was fixed by #46615 but it hasn't been back-ported to v18.x yet. That happens automatically after some time so it'll likely show up in a release in the next few weeks. You can follow the linked pull request to get notified.
@bnoordhuis are you aware whether the backport has already happened?
It's been back-ported to v19.x but not to v18.x yet. Give it a few more weeks.
Reacted by Justin BourrousseIt's been back-ported to v19.x but not to v18.x yet. Give it a few more weeks.
Is odd as I've just tried bumping from 18.15.0 to 18.16.0 and now get this
TypeError: Cannot redefine property: windowin a test.Will try again when another v18.x is released.
- added a commit that references this issue
on May 9, 2023 - added a commit that references this issue
on May 9, 2023 14 remaining items
- added 2 commits that reference this issue
on Jun 28, 2023 @Daniel8564 I'm curious why do you need to do it? isn't window available?
we have done like above to mock addEventListener:
global.window = global; window.addEventListener = () => {};- added 3 commits that reference this issue
on Jun 29, 2023 - added a commit that references this issue
on Jul 3, 2023 Hey folks, I can confirm this seems to have been fixed with the release of v18.17.0.
I was in the process (ha) of doing an upgrade of our Node environments to 18.16.0, and hit this issue.
the nullish coalescing operator (the
??=) workaround did work for me however after checking what the latest LTS was (being 18.17.0) I upgraded accordingly, removed the nullish coalescing operator from my tests, and it seems to work perfectly now.I'll update this comment if anything changes, but I think v18.17.0+ we're good to go!
Reacted by Eduardo Pinho, Daniel Manning, Stokley Onuba, Daniel Elkington, Andrii Oriekhov, Sylva Elendu, Stella Secondo, Artea, Evan Peterson, James Maher and 2 moreReacted by Maeda, Kazuya, Afraj Attar, Daniel Ramezani, Stokley Onuba, Daniel Elkington, Andrii Oriekhov, Sylva Elendu, Evan Peterson, James Maher and Brian- added a commit that references this issue
on Jul 27, 2023 - added a commit that references this issue
on Nov 15, 2023 - added a commit that references this issue
on Dec 20, 2023 - added a commit that references this issue
on Mar 12, 2024
Version
v18.16.0
Platform
21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
Error is consistent. This error did not occur when using Node 18.15.0, and also does not occur when using Node 19.9.0.
What is the expected behavior? Why is that the expected behavior?
Expected behavior is no error.
What do you see instead?
TypeError: Cannot redefine property: windowAdditional information
Same issue as: #47310
Similar to that issue, I've run into this error when running tests that use JSDom:
npm i jest jest-environment-jsdomnpx jest