I made a simple example to test package.exports.types field and the settings read as follow
"exports": {
".": {
"import": "./build/index.js",
"require": "./build/index.js",
"default": "./build/index.js",
"types": "./build/index.d.ts"
},
"./foo": {
"import": "./build/foo.js",
"require": "./build/foo.js",
"default": "./build/foo.js",
"types": "./build/foo.d.ts"
},
"./package.json": "./package.json"
},
However, when I import this package in the another project, it says
error TS2307: Cannot find module 'exports-test/foo' or its corresponding type declarations.
1 import * as a from 'exports-test/foo'
And it seems that the typescript compiler can't find the type definition file for foo.
My typescript version is 4.6.3. And I think I followed every instruction stated in the official document.
What is wrong with my settings? It'd be very helpful if you can share the repository of a working example.
You might need to add the following option in your tsconfig.json. It works in my project.
{
"compilerOptions": {
"moduleResolution": "NodeNext",
}
}
See also: https://github.com/microsoft/TypeScript/issues/49971#issuecomment-1192993398
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With