Skip to content

fix(compiler): adopt tsconfig paths/baseUrl for the ts7 checker - #197

Open
techfreaque wants to merge 1 commit into
vercel-labs:mainfrom
techfreaque:fix-ts7-paths-baseurl
Open

fix(compiler): adopt tsconfig paths/baseUrl for the ts7 checker#197
techfreaque wants to merge 1 commit into
vercel-labs:mainfrom
techfreaque:fix-ts7-paths-baseurl

Conversation

@techfreaque

Copy link
Copy Markdown

Problem

Any project whose tsconfig uses paths aliases (e.g. "@/*": ["./src/*"]) fails type-checking with:

error SC0001: Cannot find module '@/foo' or its corresponding type declarations.

even though the underlying checker (tsgo, TypeScript 7 native) fully supports paths/baseUrl natively.

Root cause

Type-checking is driven by a spawned tsgo process against a synthesized in-memory virtual tsconfig, built in packages/compiler/src/frontend/program.ts's adoptProjectConfig7(). That function only copies a small strictness-flag allowlist (ADOPTED_OPTIONS) from the project's real tsconfig.json into the options handed to tsgo — paths and baseUrl are silently dropped, so tsgo never learns about the aliases and fails to resolve them.

Fix

adoptProjectConfig7() now also adopts paths, resolving relative targets to absolute paths against the real config's directory (or its baseUrl, when set), since the virtual tsconfig fed to tsgo is written beside the entry file rather than beside the real tsconfig.json — passing relative targets through unresolved would make tsgo resolve them against the wrong base.

baseUrl itself is intentionally not forwarded: tsgo rejects it outright as a removed option ("Option 'baseUrl' has been removed... Use "paths": {"*": ["./*"]} instead."). Resolving paths targets to absolute paths up front makes forwarding baseUrl unnecessary.

Verification

  • packages/compiler: node node_modules/typescript5/bin/tsc -p tsconfig.json — 0 errors.
  • Added a regression test in packages/compiler/test/ts7/program.test.ts covering adoptProjectConfig7 via loadProgram/checkPreflight: builds a temp project with a paths alias (@/*./src/*) and an aliased import, and asserts SC0001 no longer appears in the preflight diagnostics. Confirmed the test reproduces the original bug (fails with the exact SC0001 message above) against the unpatched code, and passes with the fix.
  • Ran the full existing packages/compiler/test/ts7 suite; no new failures introduced (two pre-existing Windows path-separator test failures on this platform predate this change, verified against a clean checkout).

@vercel

vercel Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

@mabr-pcvisit is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

adoptProjectConfig7() only copies ADOPTED_OPTIONS (a small strictness-flag
allowlist) from the project's real tsconfig.json into the options handed to
the spawned tsgo (TypeScript 7 native) process. `paths` and `baseUrl` were
silently dropped, so any project using tsconfig path aliases (e.g.
`"@/*": ["./src/*"]`) hit `error SC0001: Cannot find module '@/foo'` even
though tsgo's checker fully supports `paths`/`baseUrl` natively.

Adopt `paths`, resolving relative targets to absolute paths against the
real config's directory (or its `baseUrl`, when set) rather than passing
them through unresolved: the synthesized virtual tsconfig that carries
these options to tsgo (ts7/program.ts) is written beside the entry file,
not beside the real tsconfig.json, so relative targets would otherwise
resolve against the wrong base. `baseUrl` itself is not forwarded — tsgo
rejects it outright as a removed option ("Option 'baseUrl' has been
removed... Use '\"paths\": {\"*\": [\"./*\"]}' instead."); the absolute
`paths` targets already make it unnecessary.

Adds a regression test asserting SC0001 no longer fires for an aliased
import once a tsconfig `paths` entry is in play.
@techfreaque
techfreaque force-pushed the fix-ts7-paths-baseurl branch from fbbe368 to 357d99a Compare August 22, 2026 09:29
techfreaque added a commit to techfreaque/scriptc that referenced this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant