[SDK-45] xterm.js runs code on import which crashes Web Workers
Michael-F-Bryan opened this issue · comments
When building the wasmer.sh demo in production mode (npm run build
) and serving it using the static-web-server
(wasmer run . --net
), workers will fail to start up because when they import @wasmer/sdk
to run the glue code, it also runs some top-level code from xterm.js which tries to access document.createElement()
.
Workers don't have access to the DOM, so that means our worker threads crash on startup.
Uncaught (in promise) ReferenceError: document is not defined
at index-bnmRepzq.js:1:21
at index-bnmRepzq.js:1:708
I'm guessing this is because the worker dynamically imports the bundle, and in production mode the bundle includes everything in the app, including both the wasm-bindgen
glue code and the xterm.js
library.
This can probably be resolved by splitting the bundle so @wasmer/sdk
is in a different chunk from xterm.js
(see optimizeDeps.exclude
).