From 77916d4d07ef447047fe5b07a29ce31e850b9bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Wed, 19 Nov 2025 08:06:24 +0100 Subject: [PATCH] fix: load lamejs from pre-built browser bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed MP3 export to dynamically load the pre-built lame.min.js bundle from node_modules instead of trying to import the CommonJS module. The browser bundle properly bundles all dependencies including MPEGMode and exposes a global lamejs object. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/audio/export.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/audio/export.ts b/lib/audio/export.ts index 660f330..948cc13 100644 --- a/lib/audio/export.ts +++ b/lib/audio/export.ts @@ -129,6 +129,31 @@ export function downloadArrayBuffer( URL.revokeObjectURL(url); } +/** + * Load lamejs library dynamically + */ +async function loadLamejs(): Promise { + // Check if already loaded + if (typeof window !== 'undefined' && (window as any).lamejs) { + return (window as any).lamejs; + } + + // Load the script from node_modules + return new Promise((resolve, reject) => { + const script = document.createElement('script'); + script.src = '/node_modules/.pnpm/lamejs@1.2.1/node_modules/lamejs/lame.min.js'; + script.onload = () => { + if ((window as any).lamejs) { + resolve((window as any).lamejs); + } else { + reject(new Error('lamejs failed to load')); + } + }; + script.onerror = () => reject(new Error('Failed to load lamejs script')); + document.head.appendChild(script); + }); +} + /** * Convert an AudioBuffer to MP3 */ @@ -136,9 +161,8 @@ export async function audioBufferToMp3( audioBuffer: AudioBuffer, options: ExportOptions = { format: 'mp3', bitrate: 192 } ): Promise { - // Dynamically import lamejs - use default export for CommonJS compatibility - const lameModule = await import('lamejs'); - const lamejs = lameModule.default || lameModule; + // Load lamejs library + const lamejs = await loadLamejs(); const { bitrate = 192, normalize } = options; const numberOfChannels = Math.min(audioBuffer.numberOfChannels, 2); // MP3 supports max 2 channels