Closed
Description
The JS main file uses if (typeof window === 'undefined')
to check if we're in a browser or Node.js environment...
In a web worker, the window
property doesn't exists, juste like the global
object (used by Node.js)
And the same test is used in the init function to load the WASM bytecode so just like previously, it doens't work in web workers...
As a workaround, I updated and rebuilt the library after
- removing condition to the first polyfill bloc and using
globalThis
instead ofglobal
to
!globalThis.crypto && (globalThis.crypto = {
async getRandomValues(b) {
const { randomFillSync } = await import('crypto');
randomFillSync(b);
}
});
!globalThis.performance && (globalThis.performance = {
now() {
const [sec, nsec] = process.hrtime();
return sec * 1000 + nsec / 1000000;
}
});
- testing the
fs.readFileSync
existence in theinit
main function and keep on usingglobalThis
if (fs && fs.readFileSync) {
globalThis.excelize = {};
const fs = await import('fs');
buffer = pako.ungzip(fs.readFileSync(wasmPath));
} else {
globalThis.excelize = {};
buffer = pako.ungzip(await (await fetch(wasmPath)).arrayBuffer());
}
It's not the cleaner way to fix this issue and I don't have much time to spend on this but hey... it works this way. 😅
Metadata
Metadata
Assignees
Labels
No labels