refactor(config): evaluate native Vite tsconfig paths#2546
Draft
james-elicx wants to merge 2 commits into
Draft
Conversation
commit: |
Contributor
|
Contributor
Performance benchmarksCompared 1 improved · 0 regressed · 5 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
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.
Purpose
This is an intentionally red draft to evaluate replacing vinext's hand-written tsconfig
pathsmaterialization with Vite 8's nativeresolve.tsconfigPathsimplementation.It removes the custom machinery introduced by #655 and #2504:
extendshandlingcompilerOptions.pathsinto globalresolve.aliasentriescustomResolvercustomResolverdeprecation warningnext.config.tsBoth application imports and
next.config.tsimports now delegate to native Vite tsconfig resolution.What works natively
The following targeted tests remain green:
This covers:
compilerOptions.pathsnext.config.ts@importfalling through to package exports rather than being hijacked by a global aliasStatic validation is also green. The unrelated issue #659 MDX-frontmatter regression guard was restored using a relative glob and remains green:
Intentional failing reproductions
tests/tsconfig-path-alias-build.test.tscontains three ordinary failing build tests. They are not skipped or marked as expected failures because the purpose of this draft is for CI to demonstrate the native Vite gaps clearly.1.
import.meta.glob()in bundled environmentsAn alias-based glob such as:
is not expanded using
resolve.tsconfigPathsin the bundled RSC build. The expected module never enters the bundle.The JavaScript implementation of Vite's import-glob transform calls the plugin resolver, but bundled environments switch to the native Rolldown import-glob plugin, where the tsconfig path mapping is not applied to the glob prefix.
2. Variable dynamic imports
An alias-based variable import such as:
survives into the emitted bundle with the raw alias prefix. The bundled dynamic-import-vars transform resolves/analyzes the pattern internally and does not apply native tsconfig path resolution to the static portion.
A user
resolveIdplugin is insufficient here: the bundled dynamic-import-vars path does not expose the unresolved template pattern through the normal plugin resolver before analysis.3. Pre-existing nearest-importer tsconfig limitation
A nested
lib/tsconfig.jsoncan override@/*for modules underlib/. Native ordinary import resolution discovers that config per importer, but aliased glob expansion does not. The removed vinext materialization also failed this case because it only read the root tsconfig; this test documents a pre-existing correctness limitation rather than a regression caused by this draft.This reproduction is important because a vinext fallback based on the root tsconfig would appear to remove the raw syntax while silently expanding against the wrong directory.
4.
jsconfig.jsonwhile loadingnext.config.tsThe removed vinext parser searched both
tsconfig.jsonandjsconfig.json. Vite nativeresolve.tsconfigPathsdoes not resolvenext.config.tsimports from a project that has onlyjsconfig.json. This was initially hidden when the parser unit tests were deleted; the draft now includes an ordinary failing behavioral test intests/next-config.test.ts.This is a regression from the removed custom implementation and needs either native Vite jsconfig support or a narrow vinext compatibility path.
Recommendations
Preferred: fix this in Vite
The robust solution is for Vite's bundled transforms to use the same per-importer tsconfig resolver as ordinary module resolution:
resolve.tsconfigPaths, using the importing module to select the matching tsconfig.import.meta.glob, and variable dynamic imports.This keeps tsconfig semantics in one implementation, retains Vite's native alias/build performance, and avoids framework-specific parsing.
Possible vinext fallback
If Vite cannot address this soon, vinext could add a narrowly filtered pre-transform for only:
import.meta.glob()string patternsHowever, this is only viable if vinext uses a correct per-importer resolver. Reusing the removed root-only parser would be incorrect for nested tsconfigs, project references, multiple path targets, array
extends, and future TypeScript/Vite semantics.A vinext fallback should therefore either:
The source rewrite must also be AST-based; string replacement would incorrectly rewrite comments, strings, and unrelated calls.
Draft status
This should not be merged as-is. The draft exists to: