I am trying to import a library which I published and which is generated using wasm-pack
. This is the source code of the Rust project. I tried building the package with all the target options but none of those seems to produce a package which I could successfully import in my nodejs project with ESM. Then I tried modifying the package.json file manually so that it follows what in my understanding an ESM library needs and it looks as follows:
{
"name": "fhe-wasm",
"version": "0.1.1",
"type": "module",
"exports": "./fhe_wasm.js",
"files": [
"fhe_wasm_bg.wasm",
"fhe_wasm.js",
"fhe_wasm.d.ts"
],
"module": "fhe_wasm.js",
"types": "fhe_wasm.d.ts",
"sideEffects": false
}
Unfortunately I still didn't manage to successfully import it and the and this is the error message:
I am a bit of a noob with ESM and webassembly so I would appreciate any help. Thank you
I was being stupid and didn't realize that I can simply import CommonJS library when using ESM. Simply running wasm-pack build -t nodejs
produced a library I could use.