Skip to content

Commit 2a81d0b

Browse files
ibesoragithub-actions[bot]
authored andcommitted
Default to a module worker to fix import.meta crash under
GitOrigin-RevId: 304bed40eefd1ecb08e0c579bdb8be96b3e17dc7
1 parent 3fef6a4 commit 2a81d0b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/util/web_worker.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,13 @@ import WorkerClass from './worker_class';
22

33
export function createWorker(name?: string): Worker {
44
// eslint-disable-next-line new-cap
5-
return WorkerClass.workerClass != null ? new WorkerClass.workerClass() : new self.Worker(WorkerClass.workerUrl, ({name, ...WorkerClass.workerParams}));
5+
if (WorkerClass.workerClass != null) return new WorkerClass.workerClass();
6+
// The worker bundle is valid as classic or module, but only the
7+
// module form permits `import.meta`. Downstream bundlers (Vite, Rolldown,
8+
// webpack5+) instrument every dynamic import() they see by injecting
9+
// `import.meta.url`.
10+
// In a classic worker that throws "Cannot use 'import.meta' outside a module"
11+
// the instant it parses, killing the worker silently while the main thread keeps
12+
// running normally.
13+
return new self.Worker(WorkerClass.workerUrl, ({name, type: 'module', ...WorkerClass.workerParams}));
614
}

0 commit comments

Comments
 (0)