From ea44b04bb30d04054a1f1a69b9476c506bcdb38f Mon Sep 17 00:00:00 2001 From: mk Date: Tue, 24 Mar 2026 22:03:25 -0300 Subject: [PATCH] fix: use ?worker&url import so Vite compiles the worklet TypeScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit new URL('./file.ts', import.meta.url) copies the file verbatim — the browser gets raw TypeScript and addModule() throws DOMException. Using ?worker&url tells Vite to bundle and compile the file, producing a .js output that the browser can actually execute. Co-Authored-By: Claude Sonnet 4.6 --- src/livekit/NoiseGateTransformer.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/livekit/NoiseGateTransformer.ts b/src/livekit/NoiseGateTransformer.ts index 9d292e44..b04019d6 100644 --- a/src/livekit/NoiseGateTransformer.ts +++ b/src/livekit/NoiseGateTransformer.ts @@ -7,6 +7,9 @@ Please see LICENSE in the repository root for full details. import { type Track } from "livekit-client"; import { logger } from "matrix-js-sdk/lib/logger"; +// ?worker&url tells Vite to compile the TypeScript worklet and return its URL. +// Without this, Vite copies the .ts file verbatim and the browser rejects it. +import compiledWorkletUrl from "./NoiseGateProcessor.worklet.ts?worker&url"; const log = logger.getChild("[NoiseGateTransformer]"); @@ -106,12 +109,8 @@ export class NoiseGateTransformer implements AudioTrackProcessor { log.warn("TEN-VAD WASM module unavailable — VAD disabled:", e); } - const workletUrl = new URL( - "./NoiseGateProcessor.worklet.ts", - import.meta.url, - ); - log.info("loading worklet from:", workletUrl.href); - await audioContext.audioWorklet.addModule(workletUrl); + log.info("loading worklet from:", compiledWorkletUrl); + await audioContext.audioWorklet.addModule(compiledWorkletUrl); log.info("worklet module loaded"); this.workletNode = new AudioWorkletNode(