fix: support TypeScript project references in Nuxt 4 #1384
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.
π Linked issue
#1381
β Type of change
π Description
Fixes CLI failure with "Validation failed: resolvedPaths: Required,Required,Required,Required,Required" error
when using Nuxt 4's TypeScript project references structure.
Problem:
In Nuxt 4, the main tsconfig.json only contains project references:
The actual path mappings are defined in the referenced configs (e.g., .
nuxt/tsconfig.app.json
), but theget-tsconfig
library doesn't automatically resolve these. This causedresolveImport()
to return undefined,leading to validation failures in
resolveConfigPaths()
.Solution:
Core Changes Made:
Enhanced getTSConfig() function in get-config.ts:
- Added comprehensive project references handling after the existing get-tsconfig call
- Added extensive documentation explaining the Nuxt 4 issue and solution approach
- Added fs import to enable direct file reading of referenced configs
Project References Detection Logic:
- Check if main config lacks compilerOptions.paths but has references array
- Iterate through each reference in the references array
- Resolve reference paths relative to the main tsconfig directory using
path.resolve(path.dirname(parsedConfig.path), reference.path)
Referenced Config Processing:
- Read each referenced tsconfig file directly using fs.readFileSync()
- Parse JSON content and check for compilerOptions.paths
- Handle file reading errors gracefully with try/catch and continue to next reference
BaseUrl Resolution:
- Properly resolve baseUrl relative to the referenced config's directory, not the main config
- Use path.resolve(path.dirname(referencePath), referenceConfig.compilerOptions.baseUrl)
- Fall back to main config's baseUrl if referenced config doesn't specify one
Config Merging:
- Create new config object that merges the main config structure with referenced path mappings
- Preserve all original config properties while adding the resolved paths
- Return the enhanced config object that's compatible with existing resolveImport() function
Test Coverage Added:
New Test Case (resolve-import.test.ts lines 104-117):
- Added getTSConfig import to test the enhanced function directly
- Created test that reproduces exact Nuxt 4 project structure
- Verified path resolution for multiple alias patterns: @/components, @/lib/utils, ~/components/ui
πΈ Screenshots (if appropriate)
π Checklist