If I have "module": "nodenext" in my tsconfig and my module type is commonjs (the default) then I get a TS error on import { Repeater } from "@repeaterjs/repeater":
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("@repeaterjs/repeater")' call instead.
This is because it resolves to the repeater.d.ts listed in the "types" field of your package.json, but because your package.json declares "type": "module", that repeater.d.ts is ESM.
CJS/ESM is kind of a disaster but fortunately all it takes to fix this is an export map (I'll make a PR):
If I have
"module": "nodenext"
in my tsconfig and my module type is commonjs (the default) then I get a TS error onimport { Repeater } from "@repeaterjs/repeater"
:This is because it resolves to the
repeater.d.ts
listed in the"types"
field of yourpackage.json
, but because yourpackage.json
declares"type": "module"
, thatrepeater.d.ts
is ESM.CJS/ESM is kind of a disaster but fortunately all it takes to fix this is an export map (I'll make a PR):