deepkit-framework
deepkit-framework copied to clipboard
typescript-eslint error caused by `types` field in package.json
When trying to use ESM ("type": "module"
) in my project, typescript-eslint
is unable to find types, possibly caused by "types": "./dist/cjs/index.d.ts"
in Deepkit packages' package.json
:
{
"name": "@deepkit/event",
"version": "1.0.1-alpha.74",
"description": "Deepkit async event dispatcher",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
}
}
The latest Node specs call for ignoring other package.json
fields when the exports
field is present, so this issue can pop up based on the tsconfig
module and module resolution settings, and depending on the Typescript version.
The fix is to add the types
field to the export:
"exports": {
".": {
"types": "./dist/cjs/index.d.ts",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
}
I've run into this a lot due to using beta and rc Typescript versions plus esm, and I typically use patch-package
to address it.
Thanks for the report @NexZhu and thanks for the fix @adam-coster, fixed in https://github.com/deepkit/deepkit-framework/commit/b04dae7f5f92820faf443aa3b1045f1a77b65d53