GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `--moduleResolution bundler` (formerly known as `hybrid`) by andrewbranch · Pull Request #51669 · microsoft/TypeScript

Conversation

@andrewbranch

@andrewbranch Andrew Branch (andrewbranch) commented Nov 28, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Superset of and closes Prepare module resolution for resolving TS extensions #51171: see --moduleResolution hybrid andrewbranch/TypeScript#2 for a diff between those two branches
  • Part of A Proposal For Module Resolution #50152
  • Fixes Support package.json exports outside of Node #50794
  • Fixes allow voluntary .ts suffix for import paths #37582
  • Fixes Remove "An import path cannot end with a '.ts' extension" check (rewriting out-of-scope) #38149
  • Fixes Suppressing "The import path cannot end with a '.ts' extension" error? #27481
  • Fixes Feature Request: tsconfig option "conditions=x,x,x," "exportConditions" with moduleResolve: node<any> and nodenext and or importMap support #47931
  • Closes What should the new moduleResolution setting be called? #51714

Who should use this mode?

  • ✅ Application authors who use a bundler on their TS or JS files before a runtime consumes that bundle
  • ✅ Application authors who run in Bun
  • ✅ Library authors who use a bundler to deploy a UMD bundle
  • ⚠️ Library authors who use a tool like Rollup to deploy multiple builds in different module formats—defer to advice from your build tool
  • 🚫 Anyone intending to produce modules with tsc that will run in Node or the browser without further bundling or processing
  • 🚫 Anyone intending to produce modules with tsc that will run in Deno without further bundling or processing

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

  • allowImportingTsExtensions: Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set.
  • resolvePackageJsonExports: Use the package.json 'exports' field when resolving package imports. Enabled by default in node16, nodenext, and bundler.
  • resolvePackageJsonImports: Use the package.json 'imports' field when resolving imports. Enabled by default in node16, nodenext, and bundler.
  • customConditions: Conditions to set in addition to the resolver-specific defaults when resolving imports. Valid in node16, nodenext, and bundler.

Open questions

  • Should resolvePackageJsonExports and resolvePackageJsonImports be disableable in node16 and nodenext? I see no valid reason to disable them in those modes, but I haven’t yet prohibited it.
    • There was no objection to leaving these toggleable.
  • I would like to consider allowing *.ts imports to resolve in every module resolution mode, or at least node16 and nodenext, to improve consistency and (importantly) portability of .d.ts files between modes. I think Wesley Wigham (@weswigham) has already done this in another open PR, so perhaps it won’t be too controversial.
    • I think this is doable but not necessary for merging; will follow up in a subsequent PR.
  • With four new resolution-specific compiler options, it would be nice to introduce hierarchy into tsconfig.json. That’s a non-trivial design discussion on its own, especially considering that tsconfig files can inherit from each other. Is it worth tackling that first / as part of this / in the same release cycle to avoid the expansion of root-level options here?
    • This was not considered a blocker when I mentioned it in a design meeting. If there is time to design this before 5.0 is released, we can move the new options accordingly.
  • Should bundler become the new default resolution mode for --module commonjs? I would like to rename node to node10 in a follow-up PR, and stop maintaining it going forward. It is not a good choice for anyone since Node 10 is long out of service.
    • Nathan Shively-Sanders (@sandersn) endorsed this mode being the new default. I will get more feedback in a subsequent PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Mikksrund, amalitsky, E010777, and uyarn reacted with thumbs up emoji leogreu, chrisfls, hubertkuoch, aboutsimon, rtritto, patrykszydlowski, carlansley, zyhou, sunghwan2789, robpalme, and 49 more reacted with hooray emoji chrisfls, donmccurdy, Conaclos, colinhacks, notpeelz, privatenumber, cmdcolin, bajtos, maxgfr, 7rulnik, and 17 more reacted with heart emoji macarie, colinhacks, cmdcolin, bajtos, busy-dog, unicornware, mwojtyna, janosh, brainkim, ivanbanov, and 2 more reacted with rocket emoji tonivj5, imranbarbhuiya, chrisfls, patrykszydlowski, Ige-fi, colinhacks, jaydenseric, mrm007, cmdcolin, busy-dog, and 2 more reacted with eyes emoji
All reactions
  • 👍 4 reactions
  • 🎉 59 reactions
  • ❤️ 27 reactions
  • 🚀 12 reactions
  • 👀 12 reactions
Andrew Branch (andrewbranch) added 30 commits July 28, 2022 09:20
@andrewbranch
WIP
e9f0a1a
@andrewbranch
Add extension error back unless noEmit is set
5f9cf9d
@andrewbranch
Add non-relative tests
2421cf5
@andrewbranch
Add error for importing from declaration file
660026e
@andrewbranch
Merge branch 'main' into module-resolution/minimal
2daa136
@andrewbranch
Update unit test
f49a368
@andrewbranch
Add explicit flag for importing from .ts extensions
af03675
@andrewbranch
Add module specifier resolution changes
496ef99
@andrewbranch
Add auto-import tests
458c125
@andrewbranch
Disallow relative imports into node_modules
7d64928
@andrewbranch
Ensure auto-imports don’t suggest ./node_modules;
0249e0a
@andrewbranch
Test a non-portable declaration emit issue
6242ee3
@andrewbranch
Test auto-importing TSX file
6cc0e18
@andrewbranch
Update path completions
240533a
@andrewbranch
Merge branch 'main' into module-resolution/minimal
eb9a4bb
@andrewbranch
Fix lint due to merge
619843e
@andrewbranch
Remove minimal-specific stuff
2ceb4bc
@andrewbranch
Remove minimal tests
aad7fe7
@andrewbranch
Update unit tests
7fd3e72
@andrewbranch
Merge branch 'main' into module-resolution/ts-extensions
7cca6f3
@andrewbranch
Merge branch 'main' into module-resolution/ts-extensions
ea12012
@andrewbranch
Merge branch 'main' into module-resolution/ts-extensions
8655cf9
@andrewbranch
Add options
86dd5da
@andrewbranch
Add customConditions option
8846f31
@andrewbranch
Add first tests
9bc0f07
@andrewbranch
CJS constructs are not allowed
4545afb
@andrewbranch
Add another test
e82e61d
@andrewbranch
Fix extension adding/replacing priority
038783d
@andrewbranch
Merge branch 'main' into module-resolution/ts-extensions
c55c454
@andrewbranch
Merge branch 'module-resolution/ts-extensions' into module-resolution…
870d807
…/hybrid
@brawaru Sasha Sorokin (brawaru) mentioned this pull request May 30, 2023
Switch to bundler TypeScript moduleResolution modrinth/knossos#1170
Merged
@kalvenschraut Kalven Schraut (kalvenschraut) mentioned this pull request Jun 5, 2023
support resolving aliases that have a .ts extension justkey007/tsc-alias#178
Closed
@jedwards1211

Andy Edwards (jedwards1211) commented Jun 22, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Andrew Branch (@andrewbranch) why does bundler apply the node export condition by default?

I've been trying to make a package with conditional exports that use node-fetch types for fetch, Response etc in node and Web API types otherwise, and it would be a lot easier to provide a good user experience if bundler, or some other mode, would not apply the node export condition. Because the only option is to tell users to set customConditions.

And node condition seems like a weird default for bundler since it's more common for bundlers to be used to deploy to web environments than to Node.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Jun 22, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

It doesn’t; #52940 removed it. I’ll update the PR description since docs still aren’t on the website (😬)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jedwards1211

Andy Edwards (jedwards1211) commented Jun 22, 2023

Copy link
Copy Markdown

Okay great! Thanks for letting me know

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Jun 22, 2023
Proposal: Always allow type-only imports to reference .ts extensions #54746
Merged
@andrewbranch

Andrew Branch (andrewbranch) commented Jun 22, 2023

Copy link
Copy Markdown
Member Author

Andy Edwards (@jedwards1211) No problem. I assume you’re aware that Webpack, and I assume other bundlers too, do apply the node condition even though they’re not Node 🤦🏻‍♂️

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jedwards1211

Andy Edwards (jedwards1211) commented Jun 23, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Andrew Branch (@andrewbranch) so I've learned recently...and even Deno does, somewhat surprisingly

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@merrywhether Risto Keravuori (merrywhether) mentioned this pull request Jun 27, 2023
Consider forcing extensions through linting merrywhether/config#91
Closed
@yzrmn yzrmn mentioned this pull request Jun 29, 2023
Problems with package.json wildcard exports evanw/esbuild#3201
Closed
@billti

Bill Ticehurst (billti) commented Jul 8, 2023

Copy link
Copy Markdown
Member

I found this setting fixed a long running problem I had (yay!). In trying to learn more about it I checked out https://www.typescriptlang.org/tsconfig#moduleResolution , https://www.typescriptlang.org/docs/handbook/modules.html , and https://www.typescriptlang.org/docs/handbook/module-resolution.html and none of them cover it.

What's the best reference for details (this PR discussion is rather long)? Hopefully the docs will be updated soon. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Jul 10, 2023

Copy link
Copy Markdown
Member Author

I’m updating the tsconfig.json reference now. It’s very hard to include bundler in the Module Resolution handbook page without totally rewriting it, which I’m essentially already doing over at #52593.

Naddiseo, billti, and jedwards1211 reacted with heart emoji
All reactions
  • ❤️ 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Matthew Klein (mklein994) added a commit to mklein994/playground-vue that referenced this pull request Jul 11, 2023
@mklein994
Change moduleResolution to "Bundler"
3316367
The release notes for TypeScript 5.0 recommend using "bundler" when
using tools like Vite, esbuild, Webpack, and so on.

- Docs (which unfortunately don't say much):
  https://www.typescriptlang.org/tsconfig#moduleResolution
- See also this PR: microsoft/TypeScript#51669
@lmiller1990 Lachlan Miller (lmiller1990) mentioned this pull request Aug 8, 2023
Next.js + TS not working out of the box cypress-io/cypress#27448
Closed
@Sec-ant Ze-Zheng Wu (Sec-ant) mentioned this pull request Sep 20, 2023
Module type declaration not found Sec-ant/barcode-detector#21
Closed
@cliffordfajardo Clifford Fajardo (cliffordfajardo) mentioned this pull request Oct 1, 2023
Add support for Remix v2.0.0 sergiodxa/remix-utils#228
Closed
@SebastienGllmt Sebastien Guillemot (SebastienGllmt) mentioned this pull request Oct 8, 2023
Update tsconfig build settings effectstream/effectstream#233
Open
@xiaoxian521 xiaoming (xiaoxian521) mentioned this pull request Oct 20, 2023
refactor: 使用vite-plugin-fake-server替换vite-plugin-mock,使用@faker-js/faker替换mockjs pure-admin/vue-pure-admin#763
Merged
@lachlancollins Lachlan Collins (lachlancollins) mentioned this pull request Oct 22, 2023
chore: Switch to moduleResolution: bundler TanStack/query#6217
Merged
@stijnvanhulle Stijn Van Hulle (stijnvanhulle) mentioned this pull request Oct 23, 2023
Use of --moduleResolution bundler kubb-labs/kubb#528
Closed
@daniluk4000 Danila Rodichkin (daniluk4000) mentioned this pull request Nov 5, 2023
Fix: Add "types" inside "exports" of package.json, fix ./helpers export typo faisalman/ua-parser-js#688
Merged
2 tasks done
@Ayc0 Benjamin (Ayc0) mentioned this pull request Nov 14, 2023
[moduleResolution bundler] List restrictions from initial PR in documentation microsoft/TypeScript-Website#2976
Merged
@yf-yang yf-yang mentioned this pull request Feb 23, 2024
Module resolution: Is it possible to build a repo without building its dependencies? #57505
Closed
@seoyoung81 Seoyoung Ko (seoyoung81) mentioned this pull request Mar 14, 2024
fix: eslint setting, font setting dnd-side-project/dnd-10th-7-frontend#103
Merged
2 tasks done
@ShookLyngs Shook (ShookLyngs) mentioned this pull request Jul 9, 2024
refactor(rgbpp-sdk): Support ESM package utxostack/rgbpp-sdk#246
Merged
@freemvmt Dan G (freemvmt) mentioned this pull request Aug 1, 2024
[api] adopt ESM throughout theopensystemslab/planx-new#3464
Merged
2 of 3 tasks
@aentwist Anderson Entwistle (aentwist) mentioned this pull request Aug 10, 2024
Build issue for scheduler import, with Vite P4sca1/cron-schedule#289
Closed
@uyarn wū yāng (uyarn) mentioned this pull request Feb 2, 2025
refactor: update tsconfig.json Tencent/tdesign-vue-next#4978
Merged
2 of 12 tasks
@ulivz ULIVZ (ulivz) mentioned this pull request Feb 2, 2025
refactor: enable moduleResolution: bundler to avoid @ts-ignore bytedance/UI-TARS-desktop#78
Merged
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat approved these changes
@sandersn Nathan Shively-Sanders (sandersn) sandersn approved these changes
@jakebailey Jake Bailey (jakebailey) Awaiting requested review from jakebailey
@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@andrewbranch Andrew Branch (andrewbranch)

Labels

Author: Team For Milestone Bug PRs that fix a bug with a specific milestone

Projects

PR Backlog
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Support package.json exports outside of Node Feature Request: tsconfig option "conditions=x,x,x," "exportConditions" with moduleResolve: node<any> and nodenext and or importMap support Remove "An import path cannot end with a '.ts' extension" check (rewriting out-of-scope) allow voluntary .ts suffix for import paths Suppressing "The import path cannot end with a '.ts' extension" error?
What should the new moduleResolution setting be called?

Uh oh!

There was an error while loading. Please reload this page.

13 participants

@andrewbranch @cefn @sandersn @rtritto @hubertkuoch @typescript-bot @donmccurdy @sarimarton @GeorchW @kanongil @jedwards1211 @billti @sheetalkamat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.