automerge-classic icon indicating copy to clipboard operation
automerge-classic copied to clipboard

rollup can't find wasm exports

Open BLukassen opened this issue 2 years ago • 1 comments

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"
        }),
    ]
};

BLukassen avatar Jan 22 '23 21:01 BLukassen

This looks to me like an issue with Rollup's wasm plugin rather than automerge specifically. Although I appreciate that the state of wasm module support in the JS ecosystem is quite frustrating at the moment.

alexjg avatar Feb 03 '23 15:02 alexjg