cardano-serialization-lib icon indicating copy to clipboard operation
cardano-serialization-lib copied to clipboard

(TypeError): malloc is not a function

Open zxpectre opened this issue 3 years ago • 3 comments

Hi, I'm trying to migrate to '@emurgo/cardano-serialization-lib-browser' from asmjs.

I'm using

  • "typescript": "^4.1.5",
  • "wasm-loader": "^1.3.0" OR "webassembly-loader": "^1.1.0"
  • "@emurgo/cardano-serialization-lib-browser": "^7.1.0",
  • "@craco/craco": "^6.1.2",
  • "react-scripts": "^4.0.3",
  • "[email protected]" // stuck in 4, can't update to version 5

created using CRA and CRACO to customize webpack, if i don't include this type type: "javascript/auto" then I get

Module parse failed: magic header not detected

If I include that type on webpack override, then when I call a simple function like this

let CardanoWasm: any ;
(async()=>{
  import('@emurgo/cardano-serialization-lib-browser').then((module) => {
    CardanoWasm = module;
    console.log({CardanoWasm})
    const test = CardanoWasm.BigNum.from_str("1213");
    console.log("TEST:",test.to_str())
  })
})();

I'm getting on from_str()

Unhandled Rejection (TypeError): malloc is not a function

Any clues whats happening? If there are missing types, how should I add them?

Also I think cardano_serialization_lib_bg.js might be receiving a promise, not the wasm loaded as module, so I don't know how to troubleshoot there.

Thanks.

zxpectre avatar Jul 04 '21 16:07 zxpectre

I'm having same Unhandled Rejection (TypeError): malloc is not a function, any ideas what are we doing wrong here? UPD: I wasn't using weback, but rollup. With webpack this works for me.

shroomist avatar Nov 13 '21 09:11 shroomist

@zxpectre have you solved the "malloc is not a function" issue?

kinqsley avatar Nov 22 '21 09:11 kinqsley

Using webpack 5 instead of wasm-loader solves this problem. But react-scripts currently not supports webpack 5. I've created new app without react-scripts using webpack5 and used experimental section in webpack.config.js experiments: { asyncWebAssembly: true, lazyCompilation: true, syncWebAssembly: true, topLevelAwait: true }

Hope this helps

gobeah avatar Dec 08 '21 17:12 gobeah