LedgerHQ / ledgerjs

⛔️ MOVED to monorepo "ledger-live"
https://github.com/LedgerHQ/ledger-live
Apache License 2.0
574 stars 376 forks source link

TypeError: Str is not a constrcutor #548

Open MichaelBrink opened 3 years ago

MichaelBrink commented 3 years ago

Getting a typeerror when invoking the Str constructor from @ledgerhq/hw-app-str (trying to execute a few basic stellar-sdk command)

node -v -> v.14.15.1 "@ledgerhq/hw-app-str": "^5.34.0", "@ledgerhq/hw-transport-u2f": "^5.34.0", "stellar-sdk": "^7.0.0"

code snippit:

import { default as TransportU2F } from "@ledgerhq/hw-transport-u2f";
import {default as Str} from "@ledgerhq/hw-app-str";
import StellarSdk, { Networks } from "stellar-sdk";

const getStrAppVersion = async () => {
    const transport = await TransportU2F.default.open();
    const str = new Str(transport);
    const result = await str.getAppConfiguration();
    return result.version;
} 

getStrAppVersion().then(v => console.log(v));

The error I am getting is: (node:28256) UnhandledPromiseRejectionWarning: TypeError: Str is not a constructor

Any guidance would be appreciated, ty

gre commented 3 years ago

can you try to do

import Str from "@ledgerhq/hw-app-str";

?

MichaelBrink commented 3 years ago

Yeah had that initially, but same err response (same with TransportU2F), this doesn't seem to make a difference.

@gre : I am basically running this example script and the only modification I made was changing Transport.create to TransportU2F.default.open (which I don't think is affecting the err: TypeError: Str is not a constructor )

yul761 commented 3 years ago

@gre I am sitting with a similar 'Not a constructor' issue. Could it be related to the ES6 module?

MichaelBrink commented 3 years ago

can you try to do

import Str from "@ledgerhq/hw-app-str";

?

@gre would appreciate any other suggestions, please

MichaelBrink commented 3 years ago

@gre Resolved this by using webpack to compile - this dealt with the CJS vs ES export/import inconsistency

gre commented 3 years ago

Ok thanks. Good to know, we will need to improve this in future.