Resolution depending on the order in `exports` definition

#33 · closed · 2 comments

View on GitHub ↗

nknapp

Is it intended that the resolution of exports depends on the order of properties in the `exports` definition of the package.json? * This is possibly related to https://github.com/mswjs/msw/issues/2092 but there is a reduced test-case a * I have extracted the `resolve.exports` part of the problem into this [test-case](https://github.com/nknapp/msw-solid-testing-library-bug-reproduction/blob/main/src/resolve.exports.test.ts) tldr; ``` resolve(packageJson, "./node", conditions, { "browser": false, "require": false, "conditions": [ "development", "module", "solid", "browser", "node" ] } ) ``` throws an error if the package.json contains this snippets: ``` "exports": { "./node": { "browser": null, "types": "./lib/node/index.d.ts", "require": "./lib/node/index.js", "import": "./lib/node/index.mjs", "default": "./lib/node/index.mjs" }, ... } ``` but does not throw an error if the line `browser: null` is below the line `"default": "./lib/node/index.mjs"` It seems weird to me that order should matter here, because the exports definition is an object and not an array. But I don't know too much about the details of Node's resolution algorihm, so I may be wrong.

Comments

frehner

>Within the ["exports"](https://nodejs.org/api/packages.html#exports) object, key order is significant. During condition matching, earlier entries have higher priority and take precedence over later entries. The general rule is that conditions should be from most specific to least specific in object order. https://nodejs.org/api/packages.html#conditional-exports Yup, that's the expected and correct behavior.

nknapp

I see thanks for the pointer...