I initially defined a node.js module in the following way:
function sayHello(){
// do something
}
module.exports = sayHello;
After transitioning to typescript, I created sayHello.ts
like this:
function sayHello():void {
// do something
}
export default sayHello;
This change allowed me to import from other .ts
files using:
import sayHello from "./sayHello";
However, for legacy .js
files, they now need to be updated with require('./sayHello.js').default
when exporting.
Is there a way to combine ES6 imports and ES5 require functionality?
tsconfig.json
---
{
"compilerOptions": {
"target": "es5",
"lib": [],
"checkJs": false,
"declaration": true,
"declarationMap": true,
"sourceMap": false,
"outDir": ".",
"rootDir": ".",
"importHelpers": true,
"strict": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}