Unable to resolve types with `moduleResolution` set to `node16`
rexxars opened this issue · 0 comments
rexxars commented
It looks like when using TypeScript with the moduleResolution
flag set to node16
(and using type: 'module'
in the apps package.json
), it correctly resolves the import to the index.mjs
file using the exports
declaration, but it is not able to find the type definitions.
This seems to be solved by adding a types
entry to the exports, pointing to the .d.ts
:
{
"exports": {
".": {
"node": {
"types": "./lib/index.d.ts", // <--- this one
"require": "./lib/index.cjs",
"import": "./dist/index.mjs"
},
// ...
}
}
}
This is documented in the ES Modules in Node.js section of the TypeScript handbook.