-
Notifications
You must be signed in to change notification settings - Fork 14.5k
package.json exports resolution uses fallback conditions, unlike Node #50762
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBugA bug in TypeScriptA bug in TypeScriptDomain: Node ESMLike ES Modules, but specific to Node.js support (cts, cts, mjs, mts)Like ES Modules, but specific to Node.js support (cts, cts, mjs, mts)Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Description
Activity
Metadata
Metadata
Assignees
Labels
Breaking ChangeWould introduce errors in existing codeWould introduce errors in existing codeBugA bug in TypeScriptA bug in TypeScriptDomain: Node ESMLike ES Modules, but specific to Node.js support (cts, cts, mjs, mts)Like ES Modules, but specific to Node.js support (cts, cts, mjs, mts)Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Bug Report
🔎 Search Terms
I’ve never been more confident, without searching, that I’m the first person to notice this
💻 Code
{ "exports": { ".": { "import": "./dist/main.mjs", "types": "./dist/foo.d.ts" } } }🙁 Actual behavior
Importing this package from an ESM file, in
--moduleResolution nodenext, searches for types at these locations:🙂 Expected behavior
It should not search the
typescondition, becauseimportalready matched, and contained a valid target./dist/main.mjs. Resolution here should fail for consistency with Node, which would throw a resolution error if it matched a condition but then failed to find the file specified in it.Fixing this bug may cause more harm than good. I noticed it because I claimed that a popular library would be broken under certain conditions due to misconfigured
exports, but was proven wrong in reality. I figured this may be worth documenting, but likely not worth fixing. But if someone can make a good case for why it matters, I would reconsider.