-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible issue with missing type declaration files for ESM exports #1085
Comments
This honestly seems like a TS bug as you don't seem to use
We don't support this at the moment, see #1030 |
Sorry for the lack of clarity in my question--I ended up removing Until today my exports field in my package.json looked like this. |
Also be honest I am very flummoxed about why this issue just popped up just now, since I haven't changed anything major about my microbundle config since I added the modern export a bit more than a year ago! |
Ah, that makes sense. Thanks. Do you want to supports CJS through "exports": {
"types": "./lib/index.d.mts",
"default": "./lib/index.modern.mjs"
} Keep in mind that
This happens when someone sets |
Oh wow gotcha, thanks. And thanks so much for the quick response here.
I am not sure, I think I want to focus on just maintaining current functionality, which seems like does not support CJS, right? |
I will try the solution you outlined and report back! I think I must have had them out of order before. |
Yep, this is ESM-only (through "exports": "./lib/index.modern.mjs", And this is then the correct TS representation: "exports": {
"types": "./lib/index.d.mts",
"default": "./lib/index.modern.mjs"
} As TS needs to know where to find the types for this. Please note I made a typo in the comment above, I didn't see |
Following your instructions seemed to create another error in the And here's the newly published package.json with your instructions integrated. Thanks for your help so far, this is not super urgent because I can just stick with the removed modern build... |
Also I should say just for fun I tried |
Oh shoot, try switching |
I unfortunately still see the same errors as before on arethetypeswrong |
(Last guess, I promise, feel free to ignore until I can check myself): It might be the (somewhat wonky) need to use file extensions even in the import * as utilities from './utilities';
import * as constants from './constants';
export { default as Flipper } from './Flipper';
export { default as getFlippedElementPositionsBeforeUpdate } from './flip/getFlippedElementPositions/getFlippedElementPositionsBeforeUpdate';
export * from './flip';
export { utilities, constants };
export { default as spring } from './Spring'; I think TS's ESM support requires that turn into this: import * as utilities from './utilities.js';
import * as constants from './constants.js';
export { default as Flipper } from './Flipper.js';
export { default as getFlippedElementPositionsBeforeUpdate } from './flip/getFlippedElementPositions/getFlippedElementPositionsBeforeUpdate.js';
export * from './flip.js';
export { utilities, constants };
export { default as spring } from './Spring.js'; Even if some of those are Sorry I haven't been able to get you a fix, I'll be able to clone & test locally in an hour or so. |
Alright, it's indeed that. ESM requires full file paths (i.e., So what you need to do is "correct" your entry point to look like this: // src/index.ts
import * as utilities from './utilities/index.js'
import * as constants from './constants.js'
export { default as Flipper } from './Flipper.js'
export { default as getFlippedElementPositionsBeforeUpdate } from './flip/getFlippedElementPositions/getFlippedElementPositionsBeforeUpdate/index.js'
export * from './flip/index.js'
export { utilities, constants }
export { default as spring } from './Spring/index.js' And do the same across your entire project. Yes, this means you're referring to (say) We do use TS itself to output types, which unfortunately means we can't correct these paths for you. Sorry, I know this is a pain (to put it lightly). |
Thanks for digging into this and for linking the thread. I will look at your pr--it feels like such a hack that we have to add file extensions like that, I never would have figured this out in a million years. I really appreciate your time looking into this today. |
I 100% agree. There's a couple things in newer TS versions that help somewhat, namely, allowing you to write Sorry for the long list of things to check & that the solution, as far as I understand it, is a bit miserable. |
Hi, this is possibly user error, but a recent routine release of my lib react-flip-toolkit broke type declarations-- a user filed an issue here and when I view the analysis on this page I see that types are not found.
After digging around for a bit, it seems possible based on my reading of this explanation that we need to package an
index.d.mts
alongside theindex.d.ts
automatically generated by microbundle.The text was updated successfully, but these errors were encountered: