-
Notifications
You must be signed in to change notification settings - Fork 41
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
FalseCJS
problem - severity and suggested fixes?
#21
Comments
Have you read “Types are CJS, but implementation is ESM” in the README? I started writing a response and felt like I had written it before. If the module has a default export, a default import from an ESM module will resolve to the wrong thing. Really bad. If the module doesn’t have a default export, a default import will still be (incorrectly) allowed from an ES module, binding to an object with all the named exports. Not good, but not expected API usage.
It’s not possible to know that a copy is safe without a type checker. See https://twitter.com/atcb/status/1635356255203229697 for some discussion. It will almost certainly not be safe if the source files didn’t use Node ESM-compatible module resolution (i.e. file extensions required). If they did, it might be reasonable to copy and then check for coherence with tsc?
Any
All I know is that tsup does it via a Rollup plugin, api-extractor has an implementation, and Parcel has an implementation. (I also think esbuild and swc may be interested in making one pending community consensus on |
Ah, no, didn't realize there were further explanations in the
Yeah, that's sorta my question / gut feeling about these CJS/ESM types-vs-modules mismatches. I think I understand what you're saying about the potential for problems. On the other hand, the ecosystem has apparently managed to get along so far without that being a "real" issue (although that may also be because the The potential fixes for that feel up in the air. I see you said "add an
|
Bingo. Somewhere in the Twitter thread I linked I described the most seamless way to do this, but it’s still admittedly a pain:
I am starting to think about how TypeScript can help here. It’s not cool to say “every way of doing this that doesn’t use a type checker is wrong” and then say “yeah we’re not really designed to do dual emit.” 😬 But trying to finish some docs first. |
You can track microsoft/TypeScript#54593 for proper dual emit with TypeScript. |
(I realize this is really more of a TS question than it is an
attw
question, but given our recent discussions I figured it was worth filing here. Feel free to close this once you see it.)I'm working on redoing the
redux-thunk
build setup atm, and also trying out https://github.com/egoist/tsup as a potential build tool.My current package setup looks like this:
Using the CLI wrapper I've set up for
attw
, I get this output:I'm getting that
FalseCJS
warning, and I'm guessing it's because I havedist/index.mjs
butdist/index.d.ts
.A few questions based on that:
attw
warning?tsup
doesn't currently have a way to generate.d.mts
output , per [feature] Generate esm-specific declaration files egoist/tsup#760 . Is it reasonable to copy overindex.d.ts
->index.d.mts
in this case?redux-thunk
only has the one outputindex.d.ts
file. For RTK, we have many source files, and thus many.d.ts
files:index.d.mts
file need to exist with that extension (ie, there could beindex.d.mts
andotherFile.d.ts
and that would work)? Or does every output declaration file need to have the.d.mts
extension for TS to load those properly in the ESM case?The text was updated successfully, but these errors were encountered: