ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
13.49k stars 775 forks source link

About Work.js import Blob URL Error #619

Open stark-jarvis opened 8 months ago

stark-jarvis commented 8 months ago

The problem is: "Uncaught (in promise) Error: Cannot find module 'blob:http://my.com/d9dabdb5-c1d8-41d0-a691-8ee7f9bc7ad1'"
in Chrome Browser. "my.com" is my local host name...

I use webpack and esm module core.

Here is my code:

const load = async () => { 
    const baseURL = "https://unpkg.com/@ffmpeg/core-mt@0.12.4/dist/esm";

    await ffmpeg.load({
        coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'),
        wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'),
        workerURL: await toBlobURL(`${baseURL}/ffmpeg-core.worker.js`, 'text/javascript')
};

const transcode = async ({ target: { files } }) => {

    await load();

    // some code....
}

const elm = document.querySelector('input#uploader');
elm.addEventListener('change', transcode);

webpack.config.js

return {
    entry: './src/js/index.js',
    output: {
        filename: '[name].js',
    },
    experiments: {
        asyncWebAssembly: true,
    },
    mode: env.production ? 'production' : 'development',
    devtool: 'source-map',
}

After debugging, I found that the problem lies in this piece of code: work.js

    try {
        // when web worker type is `classic`.
        importScripts(coreURL);
    }
    catch {
        // when web worker type is `module`.
        self.createFFmpegCore = (await import(
        /* @vite-ignore */ coreURL)).default;
        if (!self.createFFmpegCore) {
            throw ERROR_IMPORT_FAILURE;
        }
    }

But, I don`t kown how to fix it ! HELP !

stark-jarvis commented 8 months ago

When I checked the source code, I found something different:

 /* webpackIgnore: true */

in TypeScript code "worker.ts", but not in the "worker.js"

after add this comment in worker.js ,the error was fixed....... Amazing!!!