Skip to content

Conversation

ronantakizawa
Copy link

πŸ”— Linked issue

#1381

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to 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:

  {
    "files": [],
    "references": [
      { "path": "./.nuxt/tsconfig.app.json" }
    ]
  }

The actual path mappings are defined in the referenced configs (e.g., .nuxt/tsconfig.app.json), but the
get-tsconfig library doesn't automatically resolve these. This caused resolveImport() to return undefined,
leading to validation failures in resolveConfigPaths().

Solution:

  • Handle cases where main tsconfig.json only contains references without path mappings
  • Read referenced TypeScript config files directly to find path mappings
  • Properly resolve baseUrl relative to the referenced config's directory
  • Merge the referenced paths into the main config for compatibility

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

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@sadeghbarati
Copy link
Collaborator

sadeghbarati commented Aug 18, 2025

Thanks again for this PR

Can you check this PR comment? #1330 (comment)

Right now, with that pkg.pr.new link, you can use tsConfigPath and work with Nuxt 4, but the only annoying part is that the components.json must be created manually

Could we automatically detect the correct tsconfig file in the CLI based on the framework? I'm thinking of semver and adding some detection logic in the CLI

I want to see what your opinion is. Or is there any other better way around?

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.

2 participants