binance-api-node
binance-api-node copied to clipboard
Binance is not a function
Hi, i'm using the package in my Nuxt 3, Vue 3, Vite, Typescript Project, i just installed it and got a error when importing Binance.
With this config:

I got the next error:

When using const Binance = require('binance-api-node').default

apiKey, apiSecret & apiRoute are values form a .env file, url is https://api.binance.com or https://testnet.binance.vision
System Info "binance-api-node": "^0.11.29", Node js v16.13.2 Ubuntu 20.04
Any suggestion?
Maybe add binance-api-node in your transpile config like that:
import { defineNuxtConfig } from 'nuxt3'
export default defineNuxtConfig({
build: {
transpile: ['binance-api-node']
}
})
Hello,
I'm having the same issue. I'm writing a simple type-script app using Binance API. Very basic setup. Using 'tsc' compiler. But I don't understand a hint above (I am a newbe to js/ts/nodejs). Can you elaborate more on that?
Hello I code worked my project
import Binance from "binance-api-node";
const options ={
apiKey: "<apiKey>",
apiSecret: "<apiSecret>"
};
const client = Binance.default(options);
Can confirm the same issue.
No transpiler, node v18.3.0, running a standard package.json.
I had to run it as @suhakesikbas mentioned, using :
import Binance from 'binance-api-node'
const client = Binance.default(options)
Notice the .default here, meaning the documentation is currently erroneous.
I have the same issue.
I tried with :
import Binance from 'binance-api-node'
const client = Binance.default(options)
I have this error : error TS2339: Property 'default' does not exist on type. Any idea ?
I have the same issue.
I tried with :
import Binance from 'binance-api-node' const client = Binance.default(options)I have this error : error TS2339: Property 'default' does not exist on type. Any idea ?
Hey, the documentation has been updated to better reflect the current API.
To initialize your client, you don't need to specify the .default part. Just call Binance(options).
See the "getting started" section of the docs
@balthazar btw I think this issue is g2c now that the docs are on point ;)
Cool thank you @ubarbaxor
Sorry, but I still have the same issue :
import Binance from 'binance-api-node'
const client2 = Binance({
apiKey: apiKey,
apiSecret: apiSecret,
})
the error is :
const client2 = Binance({
^
TypeError: Binance is not a function
Hey,
Seems this keeps popping up and again.
This is behaving deferently depending on if your project is transpiled or not, if you're using ESM (import) or CommonJS (require).
Somehow the transpiling tends to break ESM exporting as it seems it's doing some shennanigans to have CommonJS compatibility.
In the future, for those with this issue : just use Binance.default() rathen than use Binance() as a constructor, and vice-versa (if Binance.default() doesn't work, use Binance()).
TL;DR : use one or the other, whichever works, depending on your build pipeline.