tastytrade / tastytrade-api-js

Javascript sdk for the tastytrade api
MIT License
67 stars 36 forks source link

TypeError: TastytradeClient is not a constructor #27

Closed m1771vw closed 7 months ago

m1771vw commented 7 months ago

Hi,

I'm following the quick start in the README:

import TastytradeClient from "@tastytrade/api"
const tastytradeClient = new TastytradeClient(baseUrl, accountStreamerUrl)
const loginResponse = await tastytradeClient.sessionService.login(usernameOrEmail, pasword)

I'm getting this error message:

const tastytradeClient = new TastytradeClient(baseUrl, accountStreamerUrl)
                         ^

TypeError: TastytradeClient is not a constructor

The baseUrl I'm using is the sandbox page.

I'm on "@tastytrade/api": "^3.1.0", I'm on node v21.5 I'm also trying to incorporate it with express and use it in a route.

Let me know what other information you need

ferdousbhai commented 7 months ago

Experiencing the same issue.

dmoss18 commented 7 months ago

@m1771vw Can I see your package.json file and (if you're using typescript) your tsconfig.json?

osdevisnot commented 7 months ago

@m1771vw and @ferdousbhai - are you able to create a smaller reproduction of your issue? Looking at the code example above, the usage of import indicates that you are using this in a project that supports modern import syntax. Ideally this should be fixed once #30 is merged and published. In case it does not, the smaller reproduction will help a lot in troubleshooting this problem.

m1771vw commented 7 months ago

@osdevisnot Yes, I'm trying to use it with modern import syntax.

Package.json:

{
    "name": "tasty-trade-api-playground",
    "version": "1.0.0",
    "description": "",
    "main": "src/index.js",
    "type": "module",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "start": "nodemon src/index.js"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "@tastytrade/api": "^3.1.0",
        "axios": "^1.6.7",
        "express": "^4.18.2",
        "lodash": "^4.17.21",
        "nodemon": "^3.1.0"
    }
}
osdevisnot commented 7 months ago

Thanks for reporting @m1771vw! I can confirm the issue. The fix for this will be available as soon as we release #30 to NPM. Stay tuned! cc: @dmoss18