Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
230 stars 124 forks source link

`BigNumFinalization.unregister is not a function` when running CSL built with `WASM_BINDGEN_WEAKREF` #647

Open elkorn opened 10 months ago

elkorn commented 10 months ago

Hi! I read https://github.com/Emurgo/cardano-serialization-lib/issues/542 and would like to avoid having to call .free on everything if possible.

So I built CSL 11.5.0 with WASM_BINDGEN_WEAKREF=1 (or so I hope). I strayed from the official docs since with nvm use it would have made me install node 12.18.1, which is causing some issues on Mac M1 - hoped I can get a pass on this, since it seems to build fine on node 16 as well.

This is the process I followed:

# 1. install rustup and wasm-pack
curl https://sh.rustup.rs -sSf | sh -s -- -y
echo 'export PATH=$HOME/.cargo/bin/:$PATH' >> $BASH_ENV
rustup install stable
rustup target add wasm32-unknown-unknown --toolchain stable
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# 2. install cmake
brew install cmake

# 3. get CSL source code
git clone https://github.com/Emurgo/cardano-serialization-lib.git

# 4. build CSL
cd ./cardano-serialization-lib
git submodule update --init --recursive
npm install
WASM_BINDGEN_WEAKREF=1 npm run rust:build-nodejs

Then I copy and link the built pkg locally. Most things seem to work fine, however I'm running into this issue:

 TypeError  BigNumFinalization.unregister is not a function
error stack:
• cardano_serialization_lib.js:2688 __destroy_into_raw
    node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js:2688:24

• cardano_serialization_lib.js:12159 set_asset
    node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js:12159:22

• task_queues:96 processTicksAndRejections
    node:internal/process/task_queues:96:5

The "offending" code:

  const policyHash = CSL.ScriptHash.from_hex(myPolicyId)
  const tokenName = CSL.AssetName.new(Buffer.from("myname"))
  const tokenAmount = CSL.BigNum.from_str("1")
  myTokens.set_asset(policyHash, tokenName, tokenAmount)

FWIW, my app runs on node 16 as well.

Any advice on this? And am I building the package right?

lisicky commented 8 months ago

Hi @elkorn ! It's better to check wasm bingen, because we generate all js side code by wasm bingen. You can try to upgrade or downgrade the version probably current one has a bug