Fix FFmpeg WASM loading: use CDN instead of local files

The 'Cannot find module as expression is too dynamic' error occurs at runtime
when FFmpeg tries to dynamically load the core module. Using CDN URLs bypasses
this bundler issue entirely since absolute URLs don't require bundler analysis.

Switched to jsdelivr CDN for FFmpeg core and WASM files - this is a proven
approach used by many projects.

Fixes: wasmLoader.ts runtime error on media conversion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-02-25 20:36:45 +01:00
parent 6d4426037c
commit 87f1384175

View File

@@ -40,9 +40,10 @@ export async function loadFFmpeg(): Promise<FFmpegType> {
console.log('[FFmpeg]', message);
});
// Files are guaranteed to exist in /wasm/ by the postinstall script
const coreURL = '/wasm/ffmpeg-core.js';
const wasmURL = '/wasm/ffmpeg-core.wasm';
// Use CDN URLs for FFmpeg core - avoids "dynamic require" bundler issues
// with local file paths that FFmpeg's internal code cannot resolve at runtime
const coreURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/core@0.12.6/dist/esm/ffmpeg-core.js';
const wasmURL = 'https://cdn.jsdelivr.net/npm/@ffmpeg/core@0.12.6/dist/esm/ffmpeg-core.wasm';
await ffmpegInstance.load({ coreURL, wasmURL });