hyperledger / iroha-javascript

JavaScript library for Iroha, a Distributed Ledger Technology (blockchain) platform.
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
94 stars 64 forks source link

Fix problem of Colleagues from Fujitsu #111

Closed appetrosyan closed 1 year ago

appetrosyan commented 1 year ago

Our colleagues from Fujitsu have asked us to provide assistance in setting up their Iroha interoperability. Their work can be found here.

https://github.com/outSH/iroha2_check

@0x009922, @antyas mentioned that you are working on something similar.

0x009922 commented 1 year ago

This issue is partially solved with the latest packages publish.

In CJS mode it works just fine. That means, in iroha2_check you could run the following:

tsc
node .

tsc will build dist/index.js file, and node . will run it in CJS mode.

However, pure ESM mode is not working yet. That means, the following will fail:

tsc --module esnext
mv dist/index.js dist/index.mjs
node dist/index.mjs

The error:

SyntaxError: Named export 'Enum' not found. The requested module '@scale-codec/core' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@scale-codec/core';

I am in the process of fixing scale-codec-js-library and its dependencies. They all should use .mjs as well.

0x009922 commented 1 year ago

Finally, JS SDK works in ESM with the following packages versions:

{
    "@iroha2/client": "^2.0.2",
    "@iroha2/crypto-core": "^0.1.1",
    "@iroha2/crypto-target-node": "^0.4.0",
    "@iroha2/data-model": "^2.0.2"
}

Now it is possible to run the following without getting ESM/CJS errors:

rm -r dist
pnpm tsc
mv dist/index.js dist/index.mjs
node dist/index.mjs