happy-dom
happy-dom copied to clipboard
Window can not be created in Bun from version 14.5.1 and higher
Describe the bug
When using new Window()
in a Bun environment, the script crash
To Reproduce Steps to reproduce the behavior:
- Install
happy-dom
version 14.5.1 or higher - Import Window and run
new Window()
- Run the script with bun
bun ./index.js
- See error
Expected behavior The program should run correctly
Screenshots If applicable, add screenshots to help explain your problem.
Device:
- OS: Windows 11
- Bun version: 1.1.4
- Version: 14.5.1 to latest
Additional context
26 | resolve();
27 | }
28 | else {
29 | this.readyStateCallbacks.push(resolve);
30 | if (this.totalTasks === 0 && !this.immediate) {
31 | this.immediate = this.window.requestAnimationFrame(this.endTask.bind(this));
^
TypeError: this.window.requestAnimationFrame is not a function. (In 'this.window.requestAnimationFrame(this.endTask.bind(this))', 'this.window.requestAnimationFrame' is undefined)
at ${PROJECT_ROOT}\node_modules\happy-dom\lib\nodes\document\DocumentReadyStateManager.js:31:38
at new Promise (:1:21)
at waitUntilComplete (${PROJECT_ROOT}\node_modules\happy-dom\lib\nodes\document\DocumentReadyStateManager.js:24:16)
at new BrowserWindow (${PROJECT_ROOT}\node_modules\happy-dom\lib\window\BrowserWindow.js:545:9)
at new Window (${PROJECT_ROOT}\node_modules\happy-dom\lib\window\Window.js:36:9)
Also reproductible on bun 1.1.4 in wsl2
I am also having the same problem but in my case I see two errors. I am using [email protected]
26 | resolve();
27 | }
28 | else {
29 | this.readyStateCallbacks.push(resolve);
30 | if (this.totalTasks === 0 && !this.immediate) {
31 | this.immediate = this.window.requestAnimationFrame(this.endTask.bind(this));
^
TypeError: this.window.requestAnimationFrame is not a function. (In 'this.window.requestAnimationFrame(this.endTask.bind(this))', 'this.window.requestAnimationFrame' is undefined)
at PROJECT_ROOT\node_modules\happy-dom\lib\nodes\document\DocumentReadyStateManager.js:31:38
at new Promise (:1:21)
at waitUntilComplete (PROJECT_ROOT\node_modules\happy-dom\lib\nodes\document\DocumentReadyStateManager.js:24:16)
at new BrowserWindow (PROJECT_ROOT\node_modules\happy-dom\lib\window\BrowserWindow.js:554:9)
at new Window (PROJECT_ROOT\node_modules\happy-dom\lib\window\Window.js:36:9)
at createDocument (PROJECT_ROOT\src\document.ts:12:18)
at new UI (PROJECT_ROOT\src\index.ts:9:29)
at PROJECT_ROOT\test\index.tsx:6:12
184 | return false;
185 | }
186 | if (ancestorNode === referenceNode) {
187 | return true;
188 | }
189 | if (!ancestorNode[PropertySymbol.childNodes].length) {
^
TypeError: undefined is not an object (evaluating 'ancestorNode[PropertySymbol.childNodes].length')
at isInclusiveAncestor (PROJECT_ROOT\node_modules\happy-dom\lib\nodes\node\NodeUtility.js:189:14)
at appendChild (PROJECT_ROOT\node_modules\happy-dom\lib\nodes\node\NodeUtility.js:24:52)
at appendChild (PROJECT_ROOT\node_modules\happy-dom\lib\nodes\element\ElementUtility.js:52:13)
at insertNode (PROJECT_ROOT\src\document.ts:48:9)
at insertExpression (PROJECT_ROOT\node_modules\solid-js\universal\dist\universal.js:85:9)
at PROJECT_ROOT\node_modules\solid-js\universal\dist\universal.js:224:9
at createRoot (PROJECT_ROOT\node_modules\solid-js\dist\server.js:58:14)
at render (PROJECT_ROOT\node_modules\solid-js\universal\dist\universal.js:222:7)
at render (PROJECT_ROOT\src\index.ts:33:5)
at PROJECT_ROOT\test\index.tsx:18:16
Bun v1.1.8 (Windows x64)
I think it's up to the Bun.js team to fix this, they seem to be aware:
There is a bug with
this
value for contextified options not having the correct prototype.
Source: https://bun.sh/docs/runtime/nodejs-apis#node-vm
Probably, this is the issue https://github.com/oven-sh/bun/issues/4205.