Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript fix for Randombytes #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rvdende
Copy link

@rvdende rvdende commented Feb 4, 2020

Hi

In a new typescript project when using bitbox-sdk by npm i bitbox-sdk:

import { BITBOX } from 'bitbox-sdk'
let bitbox = new BITBOX();
bitbox.Mnemonic.generate()

When using tsc to compile the typescript it reports these errors:

C:\Users\rouan\Desktop\work\tempbitbox>tsc test.ts
node_modules/bitbox-sdk/lib/Crypto.ts:1:8 - error TS1259: Module '"C:/Users/rouan/Desktop/work/tempbitbox/node_modules/@types/randombytes/index"' can only be default-imported using the 'esModuleInterop' flag

1 import randomBytes from "randombytes"
         ~~~~~~~~~~~

  node_modules/@types/randombytes/index.d.ts:10:1
    10 export = randomBytes;
       ~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.

node_modules/bitbox-sdk/lib/Mnemonic.ts:5:8 - error TS1259: Module '"C:/Users/rouan/Desktop/work/tempbitbox/node_modules/@types/randombytes/index"' can only be default-imported using the 'esModuleInterop' flag

5 import randomBytes from "randombytes"
         ~~~~~~~~~~~

  node_modules/@types/randombytes/index.d.ts:10:1
    10 export = randomBytes;
       ~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.


Found 2 errors.

I found that this works around the issue.

@christroutner
Copy link

Thank you for the PR. I'm not a user of Typescript, so I'm not really sure how to evaluate this. I'll try to see if any of the other committers for this repo have the prerequisite knowledge to evaluate this PR.

@SpicyPete
Copy link

Thank you for bringing this to our attention. To get around this issue quickly I recommend adding
"esModuleInterop": true to your TypeScript configuration file.
We will look into resolving all of the TS issues and improving the TS coverage of this library very soon.

@rvdende
Copy link
Author

rvdende commented Feb 18, 2020

Thanks for the feedback. I'm quite sure I tried with "esModuleInterop": true and still had the same problem, so I figured it is worth fixing in this package so others won't get the same issue.

@rvdende
Copy link
Author

rvdende commented Mar 24, 2020

Any chance to get this merged?

@elderapo
Copy link

Is there any blocker as why this hasn't been merged yet? esModuleInterop set to true breaks some other libraries and I'd like to avoid using it if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants