putdotio / putio-js

JavaScript SDK for interacting with the put.io API.
MIT License
21 stars 2 forks source link

Not a constructor error with ES6 Module import #30

Closed cvockrodt closed 3 years ago

cvockrodt commented 3 years ago

With an index.js like this:

import PutioAPI from '@putdotio/api-client'

const putioAPI = new PutioAPI({ clientID: 'OAUTH_CLIENT_ID' })

and the following package.json:

{
  "name": "putio-test",
  "version": "1.0.0",
  "description": "Test for put.io API client library",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "license": "ISC",
  "dependencies": {
    "@putdotio/api-client": "^8.16.0"
  }
}

I receive the following error:

file:///putio-test/index.js:3
const putioAPI = new PutioAPI({ clientID: 'OAUTH_CLIENT_ID' })
                 ^

TypeError: PutioAPI is not a constructor
    at file:///putio-test/index.js:3:18
    at ModuleJob.run (internal/modules/esm/module_job.js:110:37)
    at async Loader.import (internal/modules/esm/loader.js:176:24)

when using node >=13 or 12 with the --experimental-modules flag.

BatuAksoy commented 3 years ago

Hey @cvockrodt I see that PutioAPI has a default property. Normally importing directly without brackets should import the default. But here, it imports everything of module to variable. This should be a problem with tsdx.

You can use PutioAPI.default to create an api object while I am further investigating.

altaywtf commented 3 years ago

@cvockrodt could you please let us know if it doesn't work out? I'm closing the issue for now. 😊 🙏

cvockrodt commented 3 years ago

@cvockrodt could you please let us know if it doesn't work out?

Works fine, just not what I originally expected

Edit: clarity