cardano-serialization-lib
cardano-serialization-lib copied to clipboard
(TypeError): malloc is not a function
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.
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.
@zxpectre have you solved the "malloc is not a function" issue?
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