Comments (6)
@use-guesture/core
: This is not a dual package as far as Node is concerned. Theexports
conditions used aremodule
for the “ESM” files anddefault
for the CJS files. Node does not set themodule
condition, so this will never be reached by Node without specifying custom conditions. If you were to supply a custom condition ofmodule
in Node and TypeScript, a few things would happen. First, TypeScript would see everything as untyped, since only the CJS files have.d.ts
counterparts. Secondly, Node would crash, because the*.esm.js
files are CJS modules according to file extension and package.jsontype
, but use ESM syntax, which is an error. Building with a bundler that sets themodule
condition (which is surely what the package authors intended—doesn’t make much sense to run this library in Node) may work fine (in my experience, some pay attention to the package.jsontype
and others don’t), but TypeScript would still be unable to find the types if themodule
custom condition was also supplied in the tsconfig. However, the types for the CJS files would probably work fine under the default--moduleResolution bundler
config, so this scenario may accidentally work out of the box. In summary, this setup is probably working everywhere, but seems a bit fragile and confused.@razorpay/blade
: This package is completely broken in Node, because like@use-gesture/core
, the files are using ESM syntax but will be detected as CJS in Node due to file extension and lack of package.jsontype
. This would be a good validation error to add to this project.@adobe/react-spectrum
: The above explanations probably answer your question about why this is different. This package is broken in the most common, predictable way I’ve seen, which is why the tool can diagnose it with a specific explanation. The issues in the other two packages are things I haven’t specifically considered before.
Nice examples; I’ll look into adding some analysis and explanations to better diagnose these issues. Thanks!
from arethetypeswrong.github.io.
I’m going to reopen this as a way to track adding these specific problem kinds 👍
from arethetypeswrong.github.io.
Apropos of nothing, when I started assigning emoji to problem kinds, I thought there would be way fewer problem kinds 😂
from arethetypeswrong.github.io.
What does the (CJS) mean here exactly?
I forgot to answer this directly, but it may have been apparent—it’s the result of Node’s detection algorithm (mirrored in TypeScript’s modern Node resolution modes) for what kind of module a file is—i.e., what the file extension and package.json type
indicate. (If the syntax within doesn’t agree, Node will crash.)
from arethetypeswrong.github.io.
And shouldn't it be a point of concern that node16 from ESM is resolving to the CJS type definition for a package that provides ESM too?
Maybe—that’s why I render it in the table. It’s not listed as a problem because Node and TypeScript agree on what the module kind will be, and it’s not a problem to import CJS files from either ESM or CJS files. The tool doesn’t currently know whether any other files are detectably ESM or syntactically ESM, so there’s nothing that could currently indicate that the package “provides ESM too.” But I think expanding this analysis and raising a warning if ESM files exist but aren’t resolved by Node could be a good addition. On the other hand, it’s definitely possible that a package author includes ESM specifically for bundlers or the browser and intentionally leaves Node on CJS (as may be the case with @use-gesture/core
).
from arethetypeswrong.github.io.
Thanks a lot for the detailed explanations! ❤️
from arethetypeswrong.github.io.
Related Issues (20)
- TS 5.3 incompatibility HOT 3
- core/dist/types.d.ts contains triple-slash reference to ts-expose-internals HOT 1
- What to do for missing export = when it's TypeScript's fault (kinda) HOT 2
- Update MissingExportEquals.md for import default = fetch HOT 3
- lodash types are wrong (or lying?) HOT 6
- Specifying @types packages in the web UI is broken
- Trailing `/` exports don’t get detected as wildcards
- ERR_REQUIRE_ESM when upgrading from 0.13.6 to 0.13.8 HOT 2
- Indicate when JS is unanalyzable
- Understand basic UMD modules HOT 1
- Rule for missing default export / completely wrong exports?
- confusing resolution failure HOT 14
- Why are paths with colons unresolvable? HOT 2
- No errors for ESM module resolution, while errors are expected HOT 3
- [FEATURE]: Create a badge that says whether or not a package passes this repository's tests HOT 3
- Bug: This is too good
- Conditional exports syntax HOT 1
- Seeking NodeJS + TypeScript Demo Project with CJS and ESM Exports HOT 1
- Incorrectly passing when types missing in package exports HOT 3
- How to make this work with svelte? HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arethetypeswrong.github.io.