fix(resolution): an import naming the emitted .js extension resolves to its .ts source - #1706
Open
bompus wants to merge 1 commit into
Open
fix(resolution): an import naming the emitted .js extension resolves to its .ts source#1706bompus wants to merge 1 commit into
bompus wants to merge 1 commit into
Conversation
…to its .ts source Under moduleResolution node16/nodenext/bundler the specifier carries the emitted extension and no file of that name exists, so resolveRelativeImport and the aliased path returned null and every imported name fell through to bare-name matching: a method wrapping the same-named helper it imports resolved to itself. Retry with the source extensions TypeScript compiles from when the emitted file is absent; a real .js beside the .ts still wins.
This was referenced Sep 5, 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.
Fixes #1705.
What
resolveRelativeImportand the aliased path'stryWithExtnow fall back tofindSourceForEmittedSpecifier: when a specifier ends in.js/.jsx/.mjs/.cjsand no file of that exact name exists, the source extensions TypeScript compiles from are tried (.ts,.tsx,.d.ts/.tsx/.mts,.d.mts/.cts,.d.cts). Only for the TS/JS-family languages (typescript,tsx,javascript,jsx,vue,svelte,astro,arkts); a real.jsbeside the.tsstill wins because the existing as-is check runs first.Why
Under
moduleResolution: node16 | nodenext | bundlerthe emitted extension is what TypeScript requires in the specifier, so every import in such a project was invisible to the import resolver and each imported name fell through to bare-name matching. The clearest symptom is a method that wraps the same-named function it imports resolving to itself (acallsself-edge at confidence 0.4); the wider one is that cross-module edges in these projects were name guesses instead of import-backed.Measured
Real repo, 582 files, 92
.tsfiles with.jsspecifiers, indexed with and without this change on the same build:calls/importsedgesresolvedBy: importresolvedBy: exact-matchresolvedBy: fuzzycallsedgesTests
__tests__/import-emitted-specifier.test.ts: unit cases throughresolveImportPathfor.js,.jsx,.mjs,.cjs, the real-.js-wins case, an aliased@/lib/util.js, a missing target, and a non-TS language; plus an end-to-endCodeGraph.initon the wrapper-method repro asserting the edge lands on the imported function and not on the method. Full suite: no failure outside the host's known EPERM/EBUSY teardown set.