hyperledger / fabric-gateway

Go, Node and Java client API for Hyperledger Fabric v2.4+
https://hyperledger.github.io/fabric-gateway/
Apache License 2.0
150 stars 87 forks source link

Import fail in ES module format application #662

Closed ksanjaykumar1 closed 8 months ago

ksanjaykumar1 commented 8 months ago

I want to use ''@hyperledger/fabric-gateway'' in my nodejs application which is in ES module format but it's not importing correctly I tried two hacks listed online to fix it but failed.

Screenshot from 2023-12-18 13-21-13

I imported as mentioned in the error message but it failed to import Contract and Identity. Screenshot from 2023-12-18 13-21-54

I set the format type as module in the fabric gateway library but it failed.

Screenshot from 2023-12-18 16-21-52

bestbeforetoday commented 8 months ago

Contract (similar to many of the other types defined by @hyperledger/fabric-gateway) is an interface. It is just a TypeScript type definition to describe the behaviour of objects returned from Network.getContract(). There is no concrete Contract class exported. If you are using TypeScript, you should be able to import all of those types OK and, based on those types, get code assistance in your IDE and compile-time validation from the TypeScript compiler. If you are writing plain JavaScript, you can ignore all the interface types and probably only need to import the connect function (and signers to use the signers.newPrivateKeySigner function). The API documentation indicates which types are concrete classes, interfaces and functions.

ksanjaykumar1 commented 8 months ago

It works. Thank you.