--moduleResolution bundler (formerly known as hybrid) by andrewbranch · Pull Request #51669 · microsoft/TypeScript (original) (raw)

This PR introduces a new moduleResolution setting value called hybrid bundler (see #51714), designed primarily for bundlers and runtimes that include a range of Node-like resolution features and ESM syntax, but do not enforce the strict resolution rules that accompany ES modules in Node or in the browser. Special consideration has also been given for bundlers and runtimes that understand TypeScript natively and do not require compilation to JavaScript by tsc before consumption. Additionally, resolution of package.json exports and imports can be enabled/disabled/customized in configuration options. This should allow users of different bundlers and runtimes with slight variations in resolution features to customize TypeScript’s resolution settings under bundler as appropriate.

Who should use this mode?

Comparison with existing module resolution settings

classic node node16 bundler
node_modules packages
extensionless CJS only
directory index CJS only
*.ts imports
package.json exports
exports conditions always node, types;import from ESM,require from CJS;custom additions always types, import;custom additions

Module syntax restrictions

--moduleResolution bundler does not support resolution of require calls. In TypeScript files, this means the import mod = require("foo") syntax is forbidden; in JavaScript files, require calls are not errors but only ever return the type any (or whatever an ambient declaration of a global require function is declared to return).

New compiler options

Open questions