You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using code generated by emscripten in a web worker under next.js with a preloaded file, the following error happens:
*****_worker.ts:51 Uncaught (in promise) ReferenceError: window is not defined
at loadPackage (*****.js:55:19)
at eval (*****.js:208:5)
at eval (*****.js:210:3)
The generated piece of code that throws the error is the following:
(function() {
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
if (Module['ENVIRONMENT_IS_PTHREAD'] || Module['$ww']) return;
var loadPackage = function(metadata) {
var PACKAGE_PATH = '';
if (typeof window === 'object') {
PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/');
} else if (typeof process === 'undefined' && typeof location !== 'undefined') {
// web worker
PACKAGE_PATH = encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf('/')) + '/');
}
var PACKAGE_NAME = '*****.data';
var REMOTE_PACKAGE_BASE = '*****.data';
...
The underlying problem seems to actually be in Next.js, under which in web wokers typeof window === 'object' is indeed true. See the discussion: vercel/next.js#39605
For now, I use a workaround in my web worker to set a fake window containing the functions used by emscripten:
I understand that the place to fix this is next.js, but I wanted to leave a trace here for people facing this problem. Please, feel free to close as wontfix.
The text was updated successfully, but these errors were encountered:
Actually, maybe just reversing the order of our checks (first check for importScripts, and then window) might be an improvement. But, again, it might not be...
Version of emscripten/emsdk:
Failing command line:
Explanation:
When using code generated by emscripten in a web worker under next.js with a preloaded file, the following error happens:
The generated piece of code that throws the error is the following:
The underlying problem seems to actually be in Next.js, under which in web wokers
typeof window === 'object'
is indeed true. See the discussion: vercel/next.js#39605For now, I use a workaround in my web worker to set a fake window containing the functions used by emscripten:
I understand that the place to fix this is next.js, but I wanted to leave a trace here for people facing this problem. Please, feel free to close as wontfix.
The text was updated successfully, but these errors were encountered: