Closed BadCoder1337 closed 3 years ago
Could you provide an example from an actual project? I haven't had any issue in my ts projects. ESM stuff is confusing :/
Just need two files
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
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.
I'm using r6api.js as ES Module
That prevents proper usage with TypeScript. Declarations have correct default export. ES6 usage from README works only with transpiler.