Skip to content

"wasm is undefined" when using webpack #19

@fybx

Description

@fybx

Hello!

I have a wrapper module that wraps encrypt and decrypt from ecies. Here's the head of the module:

// ./crypto.js
import init, * as ecies from "ecies-wasm";
import { Key } from "./zkl-kds/key";

init();

I import and use this module in index.js:

(async () => {
  console.log("start");
  const mnemonic =
    "digital radio analyst fine casino have mass blood potato hat web capital prefer debate fee differ spray cloud";

  // for this time, skey means private key, and pkey is public
  const { publicKey: pkey, privateKey: skey } = await generateKeypair(mnemonic);
  keypair = { pkey, skey };

  const cipherText = encryptString(pkey, "message");
  console.log("encrypted string", cipherText);
  console.log("decrypted string", decryptString(skey, cipherText));
  console.log("end");
})();

And at encryptString I get the error:

Uncaught (in promise) TypeError: wasm is undefined
    encrypt webpack://zkl-crypto/./node_modules/.pnpm/[email protected]/node_modules/ecies-wasm/ecies_wasm.js?:106
    encrypt webpack://zkl-crypto/./crypto.js?:107
    encryptString webpack://zkl-crypto/./crypto.js?:69
    <anonymous> webpack://zkl-crypto/./index.js?:66
    async* webpack://zkl-crypto/./index.js?:70
    js http://127.0.0.1:5500/dist/bundle.js:30
    __webpack_require__ http://127.0.0.1:5500/dist/bundle.js:508
    <anonymous> http://127.0.0.1:5500/dist/bundle.js:651
    <anonymous> http://127.0.0.1:5500/dist/bundle.js:653
bundle.js line 41 > eval:106:9

I have enabled experiments.asyncWebAssembly in webpack.config.js. I am confident that init() is called when crypto.js module is imported. I couldn't figure out the problem on my own, so I'm here.

Thanks in advance.

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