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
Fix: move types
condition to the front
#763
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I understand that this is supposed to fix the linked issue, but doesn't this actually break esm imports now? We only generate cjs output via tsc, and an esm wrapper that re-exports from cjs, which doesn't have its own types 👀 |
Disregard, turns out I'm blind, the types line has been moved to be first in the object (although I fail to see how that matters since objects don't necessarily have an order) 🫥 |
It does if you use |
I can expand a little bit on what @kyranet mentioned. Since es2015 the keys in objects have defined order. It's an insertion order with the exception that number-like keys are at the beginning and those are sorted: var foo = {}
foo.b = null
foo.a = null
foo[10] = null
foo[1] = null
Object.keys(foo) // ['1', '10', 'b', 'a'] This fact is leveraged by the defined algorithm for
|
@Andarist Do you know how this affects top-level keys? We do have some modules that basically just do this: |
Those are not order-sensitive. It's up to the bundler~ (and runtimes) to pick up the correct field. Note that most of those fields are overriden if Does this clarify it for you? I can answer some extra questions if you have regarding this. |
That answers all my questions, thank you! |
I moved
types
condition to the front.package.json#exports
are order-sensitive - they are always matched from the top to the bottom. When a match is found then it should be used and no further matching should occur.Right now, the current setup works in TypeScript but it's considered a bug and it should not be relied upon, see the thread and the comment here. For that reason, I would like to fix all popular packages that misconfigured their
exports
this way so the bug can be fixed in TypeScript.