+Indeed, the _only_ difference between `moduleResolution: bundler` and the CommonJS `moduleResolution: nodenext` algorithm in TypeScript is import conditions, and every resolution that can be made in the ESM `moduleResolution: nodenext` algorithm will be made the same way in `moduleResolution: bundler`, with the exception of where import conditions cause them to diverge. (If there are other differences in the _real_ resolution algorithms of bundlers and Node.js, they are not reflected in TypeScript’s algorithm, so additional checking with TypeScript won’t help.) Keep in mind that bundlers came about in large part so that modules on npm, written under the assumption that only Node.js would be able to use them, could be used in the browser, which lacked a module system at the time. Bundlers would not be doing their job if their module resolution algorithms choked on Node.js code. Conditional exports _can_ be used to redirect a bundler, but doing this in a way that breaks the contract of the module that Node.js would see is arguably a bug.
0 commit comments