Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

--moduleResolution bundler (formerly known ashybrid)#51669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

andrewbranch
Copy link
Member

@andrewbranchandrewbranch commentedNov 28, 2022
edited
Loading

This PR introduces a newmoduleResolution setting value calledhybridbundler (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 bytsc before consumption. Additionally, resolution of package.jsonexports andimports 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 underbundler as appropriate.

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 withtsc that will run in Node or the browser without further bundling or processing
  • 🚫 Anyone intending to produce modules withtsc that will run in Deno without further bundling or processing

Comparison with existing module resolution settings

classicnodenode16bundler
node_modules packages
extensionlessCJS only
directory indexCJS only
*.ts imports
package.jsonexports
exports conditionsalwaysnode,types;
import from ESM,
require from CJS;
custom additions
alwaystypes,import;
custom additions

Module syntax restrictions

--moduleResolution bundler does not support resolution ofrequire calls. In TypeScript files, this means theimport mod = require("foo") syntax is forbidden; in JavaScript files,require calls are not errors but only ever return the typeany (or whatever an ambient declaration of a globalrequire 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 innode16,nodenext, andbundler.
  • resolvePackageJsonImports: Use the package.json 'imports' field when resolving imports. Enabled by default innode16,nodenext, andbundler.
  • customConditions: Conditions to set in addition to the resolver-specific defaults when resolving imports. Valid innode16,nodenext, andbundler.

Open questions

  • ShouldresolvePackageJsonExports andresolvePackageJsonImports be disableable innode16 andnodenext? 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 leastnode16 andnodenext, to improve consistency and (importantly) portability of .d.ts files between modes. I think@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.
  • Shouldbundler become the new default resolution mode for--module commonjs? I would like to renamenode tonode10 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.
    • @sandersn endorsed this mode being the new default. I will get more feedback in a subsequent PR.

Mikksrund, amalitsky, E010777, and uyarn reacted with thumbs up emojileogreu, chrisfls, hubertkuoch, aboutsimon, rtritto, patrykszydlowski, carlansley, zyhou, sunghwan2789, robpalme, and 49 more reacted with hooray emojichrisfls, donmccurdy, Conaclos, colinhacks, notpeelz, privatenumber, cmdcolin, bajtos, maxgfr, 7rulnik, and 17 more reacted with heart emojimacarie, colinhacks, cmdcolin, bajtos, busy-dog, unicornware, mwojtyna, janosh, brainkim, ivanbanov, and 2 more reacted with rocket emojitonivj5, imranbarbhuiya, chrisfls, patrykszydlowski, Igetin, colinhacks, jaydenseric, mrm007, cmdcolin, busy-dog, and 2 more reacted with eyes emoji
brawaru added a commit to brawaru/modrinth-knossos that referenced this pull requestMay 30, 2023
This is a new resolution algorithm in TypeScript that closely matchesthe one present in popular bundlers like Vite and Webpack.More details:https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/#moduleresolution-bundlermicrosoft/TypeScript#51669
@jedwards1211
Copy link

jedwards1211 commentedJun 22, 2023
edited
Loading

@andrewbranch why doesbundler apply thenode export condition by default?

I've been trying to make a package with conditional exports that usenode-fetch types forfetch,Response etc innode and Web API types otherwise, and it would be a lot easier to provide a good user experience ifbundler, or some other mode, would not apply thenode export condition. Because the only option is to tell users to setcustomConditions.

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

@andrewbranch
Copy link
MemberAuthor

andrewbranch commentedJun 22, 2023
edited
Loading

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

@jedwards1211
Copy link

Okay great! Thanks for letting me know

@andrewbranch
Copy link
MemberAuthor

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

@jedwards1211
Copy link

jedwards1211 commentedJun 23, 2023
edited
Loading

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

@billti
Copy link
Member

I found this setting fixed a long running problem I had (yay!). In trying to learn more about it I checked outhttps://www.typescriptlang.org/tsconfig#moduleResolution ,https://www.typescriptlang.org/docs/handbook/modules.html , andhttps://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!

@andrewbranch
Copy link
MemberAuthor

I’mupdating the tsconfig.json reference now. It’s very hard to includebundler 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

mklein994 added a commit to mklein994/playground-vue that referenced this pull requestJul 11, 2023
The release notes for TypeScript 5.0 recommend using "bundler" whenusing 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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sheetalkamatsheetalkamatsheetalkamat approved these changes

@sandersnsandersnsandersn approved these changes

@jakebaileyjakebaileyAwaiting requested review from jakebailey

@weswighamweswighamAwaiting requested review from weswigham

@DanielRosenwasserDanielRosenwasserAwaiting requested review from DanielRosenwasser

@RyanCavanaughRyanCavanaughAwaiting requested review from RyanCavanaugh

Assignees

@andrewbranchandrewbranch

Labels
Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone
Projects
Archived in project
Milestone
No milestone
13 participants
@andrewbranch@cefn@sandersn@rtritto@hubertkuoch@typescript-bot@donmccurdy@sarimarton@GeorchW@kanongil@jedwards1211@billti@sheetalkamat

[8]ページ先頭

©2009-2025 Movatter.jp