TS7056

The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("...")' call instead.

Broken Code ❌

const myModule = require('./esmodule.mjs');
tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs"
  }
}

Fixed Code ✔️

const myModule = await import('./esmodule.mjs');
tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs"
  }
}

Alternative:

import myModule from './esmodule.mjs';
tsconfig.json
{
  "compilerOptions": {
    "module": "esnext"
  }
}

CommonJS require() cannot import ES modules. Use dynamic import() or switch to ES modules.