Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

R6API class is under double default export #67

Closed
BadCoder1337 opened this issue Aug 24, 2021 · 2 comments · Fixed by #70
Closed

R6API class is under double default export #67

BadCoder1337 opened this issue Aug 24, 2021 · 2 comments · Fixed by #70

Comments

@BadCoder1337
Copy link
Contributor

I'm using r6api.js as ES Module

PS C:\Users\NO_RUSSIAN_SYMBOLS\Projects\temp> node
Welcome to Node.js v16.3.0.
Type ".help" for more information.
> import("r6api.js").then(m => r6api = m)
Promise { <pending> }
> r6api.default.default
[class R6API]

That prevents proper usage with TypeScript. Declarations have correct default export. ES6 usage from README works only with transpiler.

@danielwerg
Copy link
Owner

Could you provide an example from an actual project? I haven't had any issue in my ts projects. ESM stuff is confusing :/

@BadCoder1337
Copy link
Contributor Author

BadCoder1337 commented Aug 29, 2021

Just need two files

  • Create package.json like this to switch Node to native ES Modules by default / use .mjs extension.
{
    "type": "module",
    "dependencies": {
        "r6api.js": "2.1.0"
    }
}
  • yarn install
  • Create test.js like this
import R6API, { constants, typings, utils/* , fetch */ } from "r6api.js" // error for fetch import
console.log("R6API", R6API.toString(), R6API.default?.toString())
console.log("constants", constants.toString())
console.log("typings", typings.toString())
console.log("utils", utils.toString())
// console.log("fetch", fetch.toString())
  • node test.js

First string will be R6API [object Object] class R6API { ... }. R6API is not a class. R6API is already a default import, so R6API.default type is any causing a TS error.

Doesn't import propely in Node 12, 14, 16.

danielwerg added a commit that referenced this issue Aug 29, 2021
Re-export module as MJS

closes #67
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants