Let's say I have a module in TypeScript:
export default function myModule(name: string): void {
alert(`Hello, ${name}!`)
}
When I run tsc to build the above code, and try to import the generated code through Node.js (pure JavaScript):
const myModule = require('./dist/myModule.js')
myModule('Luiz') // ERROR! `myModule` is `undefined`
The only way to make it work is by using .default after the require(), which is not what I want:
// ↓↓↓↓↓↓↓↓
const myModule = require('./dist/myModule.js').default
myModule('Luiz') // Now it works.
How can I make TypeScript generate an output that I can use later as a Node.js module (as I'm publishing the package into NPM) without that .default property? Just like this:
const myModule = require('my-module')