Fix ESM resolution by adding file extensions to imports#5656
Open
iclanton wants to merge 4 commits intomicrosoft:mainfrom
Open
Fix ESM resolution by adding file extensions to imports#5656iclanton wants to merge 4 commits intomicrosoft:mainfrom
iclanton wants to merge 4 commits intomicrosoft:mainfrom
Conversation
…es (microsoft#5650)" This reverts commit 7e14cda.
…ce import/extensions ESLint rule
…mportExtensions Migrates all relative import/export specifiers across the repo to include explicit .ts/.tsx file extensions. This enables TypeScript's rewriteRelativeImportExtensions compiler option to produce correct .js extensions in compiled output, fixing ESM resolution under Node.js. Also includes: - heft-typescript-plugin: inject rewriteRelativeImportExtensions and allowImportingTsExtensions in tsconfigLoader; enhance wrapWriteFile to rewrite .js specifiers when jsExtensionOverride is set; remove the old addJsExtensionToImports approach - ESLint import/extensions rule added to local-eslint-config - ESLint rule disabled for ts-loader and composite-test projects - require() calls use .js extensions (not rewritten by TS) - esm-node-import-test: new build-test validating ESM imports work - rush.json: register esm-node-import-test project Fixes microsoft#5644
TheLarkInn
approved these changes
Feb 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR migrates all relative import/export specifiers across the repo to include explicit
.ts/.tsxfile extensions, enabling TypeScript'srewriteRelativeImportExtensionscompiler option. This ensures that compiled.jsoutput includes proper file extensions in import specifiers, fixing Node.js ESM resolution when consuming Rush Stack packages via their ESM entry points.Further work toward resolving #5644
Details
Approach:
Reverted the earlier addition of
"node"entries fromexportsinpackage.jsonfiles (Temporarily add "node" entries to exports in package.json files #5650), restoring ESM entry points for packages that had them.Enabled
rewriteRelativeImportExtensionsin the local rigtsconfig.jsonconfigurations and added theimport/extensionsESLint rule tolocal-eslint-configto enforce.tsextensions in source imports going forward.Added
.tsextensions to all relative imports (~1,251 files changed) across the repo so TypeScript can rewrite them to.jsin compiled output.Updated
@rushstack/heft-typescript-pluginto:rewriteRelativeImportExtensionsandallowImportingTsExtensionsintsconfigLoaderwrapWriteFileto rewrite.jsspecifiers whenjsExtensionOverrideis setaddJsExtensionToImportsapproach (now handled natively by the TypeScript compiler)require()calls use.jsextensions directly (TypeScript does not rewrite these).ESLint rule disabled for
ts-loaderand composite-test projects where it doesn't apply.New
esm-node-import-testbuild-test added to validate that ESM imports resolve correctly at runtime under Node.js.Backwards compatibility: The
addJsExtensionToImportsoption in@rushstack/heft-typescript-pluginis removed (breaking for anyone using it), replaced by the standard TypeScriptrewriteRelativeImportExtensionsmechanism. This is reflected as aminorversion bump.How it was tested
rush buildcompletes successfully across the repo with the new import extensions andrewriteRelativeImportExtensionsenabled.esm-node-import-testbuild-test validates that ESM imports with.jsextensions resolve correctly at runtime under Node.js (uses--no-warningsto suppress expectedMODULE_TYPELESS_PACKAGE_JSONwarnings on Node 22+).import/extensionsrule catches missing.tsextensions in new code.Impacted documentation
None.