When I use wasm-pack
to compile some rust code into webassembly, specifically with the option --target browser
(which is the default), these are the files that I see in typescript/deps/ed25519xp
:
- ed25519xp_bg.wasm
- ed25519xp_bg.d.ts
- ed25519xp.d.ts
- ed25519xp.js
- package.json
This is how my typescript file looks:
// typescript/src/index.ts
export { seed_from_phrase, gen_keypair } from "ed25519xp";
The contents of my package.json are as follows:
{
"name": "ed25519",
"version": "0.1.0",
"description": "ed25519",
"main": "typescript/dist/bundle.js",
"types": "typescript/src/index.ts",
"dependencies": {
"ed25519xp": "file:typescript/deps/ed25519xp"
},
"devDependencies": {
"@types/node": "^13.7.1",
"typescript": "^3.7.5",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-multi-entry": "^3.0.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-wasm": "^3.0.0",
"rollup": "^1.31.1",
"rollup-plugin-typescript2": "^0.26.0"
}
}
And this is my rollup configuration:
// rollup.config.js
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import multi from "@rollup/plugin-multi-entry";
import wasm from "@rollup/plugin-wasm";
export default {
input: [
"typescript/deps/ed25519xp/ed25519xp_bg.wasm",
`typescript/src/index.ts`
],
output: {
sourcemap: true,
format: "iife",
name: "ed25519",
file: `typescript/dist/bundle.js`
},
plugins: [
multi(),
resolve({
browser: true,
extensions: [".js", ".ts", ".wasm"]
}),
commonjs({
include: [
`typescript/**/*.js`,
`typescript/**/*.ts`,
`typescript/**/*.wasm`,
"node_modules/**"
]
}),
typescript(),
wasm()
// If we're building for prod (npm run build
// instead of npm run dev), minify
// terser()
]
};
After running the bundle command with rollup (node node_modules/.bin/rollup -c
), I encounter this error message:
(!) Missing exports
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
typescript/deps/ed25519xp/ed25519xp.js
memory is not exported by typescript/deps/ed25519xp/ed25519xp_bg.wasm
...
However, when examining the .wasm file as WAT, it seems that the exports are present:
...
(func $seed_from_phrase (export "seed_from_phrase") (type $t6) (param $p0 i32) (param $p1 i32) (result i32)
...
(func $gen_keypair (export "gen_keypair") (type $t6) (param $p0 i32) (param $p1 i32) (result i32)
...
You can find the entire repository at https://github.com/nmrshll/ed25519/tree/943fc841693401acc64260fc19d4dda08ae3503d.
How can I resolve the "Missing exports" issue during bundling?