// js-file.js
function exportFunction() {
  console.log("exported function");
}

// exportFunction();

export { exportFunction };
// js-file.d.ts
declare module "js-file" {
  export function exportFunction(): void;
}
// ts-file.ts
import { exportFunction } from "./js-file.js";

exportFunction();
{
  "compilerOptions": {
    "module": "ESNext"
  },
  "ts-node": {
    "esm": true
  }
}
{
  "type": "module"
}

I am trying to make it work with ESM (it works with commonjs). If I update declaration file to export declare function exportFunction(): void;, I can compile the code and then a new error occurs.

n/ts-file.js:2
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope

I am trying to debug the issue for a while now but unable to find a solution.

0

There are 0 best solutions below