input-output-hk / cardano-js-sdk

JavaScript SDK for interacting with Cardano, providing various key management options, with support for popular hardware wallets
https://input-output-hk.github.io/cardano-js-sdk/
Apache License 2.0
216 stars 58 forks source link

ESM Support #1372

Closed joacohoyos closed 3 weeks ago

joacohoyos commented 1 month ago

Summary

Hi Everoyne!

Creating this issue cause at jpg.store we were trying to use Blaze (which internally uses cardano-js-sdk)and at the same time using the sdk directly for a lot of datum building and other cardano relate stuff and noticed several issues while using the library in ESM mode. Talking with people at butane, they had issues with ESM too, so it seems its not an problem only for us.

@pocesar ( our js wizard) did an analysis of the codebase and even try fixing it with no luck. Here there is a rough summary of the findings he got and some output he gave us.

@pocesar and also @micahkendall and @ezepze from butane recommended actually using a build step through something like esbuild, rollup, tsup instead of relying on correctness from the tsc compiler.

Think this is a major issue to try to address as ESM is starting to get more and more adoption and CJS is starting to almost be unproductive to create new codebases with given a lot of the newer libraries are starting to ship with esm support only.

Steps to reproduce the bug

https://github.com/joacohoyos/cardano-sdk-esm-issue

Here there is a repo which you already start getting issue with if you try to run it.

It start with libsodium issues, but even if you fix those you then start getting different issues with different pieces of the library.

According to @pocesar another quick way to see the issue is doing a --target ESNext --module ESNext --moduleResolution Bundler inside each workspace module.

Actual Result

Getting multiple issues when using with ESM

Expected Result

Library works both with CJS and ESM environemntes

SDK version

^0.35.2

Environment type

Environment details

Node: 20.9.0

mkazlauskas commented 1 month ago

Hi, we're planning to replace tsc with a bundler and include some transpiled dependencies. In a meantime, consumer apps in Node.js have to either use cjs or a bundler

AngelCastilloB commented 1 month ago

@joacohoyos please try with version 0.35.4

joacohoyos commented 3 weeks ago

Seems to be working. Thanks so much for the work done