When using TypeScript's new nodenext/node16module setting, and using the new exports field in the package.json file, TypeScript no longer looks at the root types field for looking for type declarations.
Instead, you also need to add a types field within the exports field. The old types field should be kept for compatibility with older TypeScript versions.
When using TypeScript's new
nodenext
/node16
module
setting, and using the newexports
field in thepackage.json
file, TypeScript no longer looks at the roottypes
field for looking for type declarations.Instead, you also need to add a
types
field within theexports
field. The oldtypes
field should be kept for compatibility with older TypeScript versions.See TypeScript docs on ECMAScript Modules in Node.js.
Example (copied from TypeScript docs) at https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing: