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 59 forks source link

core: rxjs is not optional #1001

Open klntsky opened 10 months ago

klntsky commented 10 months ago

Summary

I'm trying to initialize a project using @cardano-sdk/core and node fails

Steps to reproduce the bug

  1. Initialize a new npm package with npm & nodejs v18.18.2
  2. set type:module in package.json
  3. Add @cardano-sdk/core to the dependencies
  4. enter node repl and import it

Actual Result


[nix-shell:~/c/cjssdk-test]$ node --experimental-specifier-resolution=node
(node:2382229) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
Welcome to Node.js v18.18.2.
Type ".help" for more information.
> const c = await import('@cardano-sdk/core')
Uncaught:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rxjs' imported from /home/me/c/cjssdk-test/node_modules/@cardano-sdk/core/dist/esm/CardanoNode/util/bufferChainSyncEvent.js
    at __node_internal_captureLargerStackTrace (node:internal/errors:496:5)
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:890:9)
    at moduleResolve (node:internal/modules/esm/resolve:939:20)
    at defaultResolve (node:internal/modules/esm/resolve:1132:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:835:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18) {
  code: 'ERR_MODULE_NOT_FOUND'
}
>

Expected Result

Importing works

SDK version

0.21.0

Environment type

Environment details

nodejs v18.18.2

rhyslbw commented 10 months ago

Why is rxjs a peer dependency @mkazlauskas ?

mkazlauskas commented 10 months ago

core package was supposed to only import types from rxjs in order to define ObservableCardanoNode interface, but clearly it's no longer the case. We should probably hoist bufferChainSyncEvent to projection package.

AngelCastilloB commented 1 week ago

This issue should be solved in version 0.40.0