Node.js + TypeScript CommonJS import

When importing libphonenumber-js 1.10.49 from a CommonJS TypeScript module (with module type and resolution = node16), the TypeScript compiler fails with the following error:

node_modules/libphonenumber-js/index.d.cts:18:8 - error TS1479: 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("./types.d.js")' call instead.

18 } from './types.d.js'; ~~~~~~~~~~~~~~

Found 1 error in node_modules/libphonenumber-js/index.d.cts:18

The .d.js file is imported in the examples.*.json and metadata.*.json .d.cjs type definitions too.

Changing the import to ./types.d.cjs fixes the error.

A sample repository can be found at https://github.com/lbevilacqua/libphonenumber-js-issue/

Assignee Loading
Time tracking Loading