Skip to content

rollup can't find wasm exports #524

Open
@BLukassen

Description

I can't get automerge running in browser with rollup.

none of the exports from the wasm file will be recognized
-> [name] is not exported by node_modules/@automerge/automerge-wasm/bundler/automerge_wasm_bg.wasm
e.g.: automerge_generateSyncMessage is not exported by ...

what is missing for rollup

src/index.mjs

import * as Automerge from "@automerge/automerge";
export default () => {
    let doc = Automerge.init();
    let actorId = Automerge.getActorId(doc);
    console.log("Automerge", actorId);
}

automerge.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Automerge</title>
</head>
<body>
<h1>Automerge</h1>

<script type="module">
    import main from "./dist/browser/src/index.js";
    main();
</script>
</body>
</html>

rollup.config.js

import { nodeResolve } from '@rollup/plugin-node-resolve';
import { wasm }        from '@rollup/plugin-wasm';
import commonjs        from '@rollup/plugin-commonjs';

export default {
    input: 'src/index.mjs',
    output: {
        sourcemap: true,
        preserveModules: true,
        dir: 'dist/browser',
        format: 'es'
    },
    plugins: [
        commonjs(),
        nodeResolve({
            browser: true,
            extensions: [".js", ".mjs", ".ts", ".wasm"],
            exportConditions: ["module"],
            mainFields: ["main", "module", "browser"]
        }),
        wasm({
            targetEnv: "browser"
        }),
    ]
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions