Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollup can't find wasm exports #524

Open
BLukassen opened this issue Jan 22, 2023 · 1 comment
Open

rollup can't find wasm exports #524

BLukassen opened this issue Jan 22, 2023 · 1 comment

Comments

@BLukassen
Copy link

BLukassen commented Jan 22, 2023

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

@alexjg
Copy link
Contributor

alexjg commented Feb 3, 2023

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.

issackelly pushed a commit to issackelly/automerge that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants