javascriptmediainfo

mediainfo.js 0.3.5 giving error loading MediaInfoModule.wasm


I have an AWS javascript lambda using CommonJS modules running under Node.js 18.x. (I know it's a bit old and just went out of support). I'm running currently with mediainfo.js 0.1.9 and everything works fine. I tried to upgrade to mediainfo.js 0.3.5 and, after making appropriate adjustments (like changing new MediaInfoFactory(..) to mediaInfoFactory(..)), I get the following errors when I'm trying to run:

2025-07-25T05:29:49.977Z    da5eb22d-0494-41dd-8aa8-194b0e8b42be    ERROR   failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): invalid value type 0x64 @+249
2025-07-25T05:29:49.977Z    da5eb22d-0494-41dd-8aa8-194b0e8b42be    ERROR   Aborted(CompileError: WebAssembly.instantiate(): invalid value type 0x64 @+249)
2025-07-25T05:29:49.977Z    da5eb22d-0494-41dd-8aa8-194b0e8b42be    ERROR   RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): invalid value type 0x64 @+249). Build with -sASSERTIONS for more info.
    at abort (/var/task/node_modules/mediainfo.js/dist/cjs/MediaInfoModule.cjs:297:15)
    at instantiateArrayBuffer (/var/task/node_modules/mediainfo.js/dist/cjs/MediaInfoModule.cjs:343:9)
    at async createWasm (/var/task/node_modules/mediainfo.js/dist/cjs/MediaInfoModule.cjs:417:22)
    at async /var/task/node_modules/mediainfo.js/dist/cjs/MediaInfoModule.cjs:2645:23

I temporarily built a custom locateFile function and passed it to the 0.3.5 mediaInfoFactory and I verified that I'm loading MediaInfoModule.wasm from the correct location. I also verified that offset 249 (decimal) = 0xf9 (hex) indeed contains a x'64'.

The error is on this statement: let mi = await mediaInfoFactory({chunkSize: CHUNK_SIZE, coverData: false, format: 'JSON'});

and the require that I'm using is: const { mediaInfoFactory } = require('mediainfo.js');

I'm not sure what I'm doing wrong or if it's something with my environment or what.

I appreciate any help. Thanks, Gary


Solution

  • TL;DR Node 18 is not supported.

    👉️ Solution: Switch to at least Node 20 or use an older release of mediainfo.js.

    Explanation:

    0x64 (decimal 100) is the LEB-128 encoded value of the type externref in the WebAssembly binary.

    Node 18’s V8 (8.9-ish) was released before the reference-types proposal reached phase-4, so the byte that encodes externref is illegal → the decoder throws "invalid value type".

    or, if the engine understands the reference-types proposal, the new type bytes

    V8 8.9 (Node 18) does not know those two new bytes, so 0x64 is simply illegal and the whole module is rejected.

    Full disclosure: I am the maintainer of mediainfo.js.