Skip to content

README JavaScript example fails to instantiate generated WASM module #56

Description

@huangyxi

The JavaScript snippet from the README did not work for me. The following code successfully instantiated and executed the generated module:

import fs from 'fs';
const bytes = fs.readFileSync('add.wasm');
const { instance } = await WebAssembly.instantiate(
    bytes,
    {
        Math: { pow: Math.pow }
    }
);
console.log(instance.exports.add(5, 3));

The Math: { pow: Math.pow } import appears to be required. Without it, the example did not work in my setup.

The Julia code from the README worked unchanged:

using WasmTarget

function add(a::Int32, b::Int32)::Int32
    return a + b
end

wasm_bytes = compile(add, (Int32, Int32))
write("add.wasm", wasm_bytes)

Environment

OS: Linux (x86_64-linux-gnu)
Julia: 1.12.6
WasmTarget.jl: v0.3.15
Node.js: v26.3.1

I don't have any prior experience with either this package or WebAssembly, so I may be missing something. I'm simply reporting what I observed while following the README example and sharing the changes that made it work on my system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions