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

TypeError: Binance is not a function #640

Open
bennycode opened this issue Aug 7, 2023 · 3 comments
Open

TypeError: Binance is not a function #640

bennycode opened this issue Aug 7, 2023 · 3 comments

Comments

@bennycode
Copy link
Contributor

I am working in a TypeScript project using ES Modules (ESM) and noticed that it doesn't work out-of-the-box with the types provided from binance-api-node/index.d.ts.

Using the following code:

import Binance from 'binance-api-node';

const client = Binance({
  apiKey: process.env.BINANCE_API_KEY!,
  apiSecret: process.env.BINANCE_API_SECRET!,
});

I ran into this error:

TypeError: Binance is not a function

Here is what I did in my code to fix the situtation:

import Binance from 'binance-api-node';

const esmBinanceHack: typeof Binance = (Binance as any).default;
const client = esmBinanceHack({
  apiKey: process.env.BINANCE_API_KEY!,
  apiSecret: process.env.BINANCE_API_SECRET!,
});

Is anyone else experiencing a similar problem?

@OliverLu01
Copy link

OliverLu01 commented Sep 5, 2023

I solved this by deleting my tsconfig file and installing a new one using npx tsconfig.json with option 'node'. B4 that I tried ur solution but lost typechecking and linting.

@alienatl

This comment was marked as spam.

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

No branches or pull requests

4 participants
@bennycode @OliverLu01 @alienatl and others