In my project (latest commit) I have two exports in my package.json:
"exports": {
".": "./dist/index.js",
"./react-lazy": "./dist/react-lazy.js"
},
Using this from a JS project works fine, but TS projects complain about not finding the types after I split one module into a subpath export.
I then tried the "expanded" exports version I saw mentioned in another answer:
"exports": {
".": {
"import": "./dist/index.js",
"types": "./types/index.d.ts"
},
"./react-lazy": {
"import": "./dist/react-lazy.js",
"types": "./types/react-lazy.d.ts"
}
},
No go.
I then tried an alternative approach using typesVersion
:
"typesVersions": {
"*": {
".": "./types/index.d.ts",
"./react-lazy": "./types/react-lazy.d.ts"
}
},
Also, no go. What gives? Now I am a bit confused as to what is the problem here.
When trying this out, I npm link
up this project and npm link @fatso83/retry-dynamic-import
from the test project and run tsc --lib es2015,dom --noEmit main.ts
.
I am basically just testing out whether these lines passes the compiler or not:
import { dynamicImportWithRetry } from "@fatso83/retry-dynamic-import";
import reactLazy from "@fatso83/retry-dynamic-import/react-lazy";
Currently, all above attempts end up with
$ tsc --lib es2015,dom --noEmit main.ts
main.ts:3:40 - error TS2307: Cannot find module '@fatso83/retry-dynamic-import' or its corresponding type declarations.
3 import { dynamicImportWithRetry } from "@fatso83/retry-dynamic-import";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If I was just exporting index.js, all would be good, as this works:
"exports": "./dist/index.js",
"types": "./types/index.d.ts",
That will make the first line pass, but not the second.