Skip to content

fix: resolve.tsconfigPaths: true not applied in test environment#10087

Closed
MdSadiqMd wants to merge 3 commits intovitest-dev:mainfrom
MdSadiqMd:debug/resolve-tsconfig-path-error
Closed

fix: resolve.tsconfigPaths: true not applied in test environment#10087
MdSadiqMd wants to merge 3 commits intovitest-dev:mainfrom
MdSadiqMd:debug/resolve-tsconfig-path-error

Conversation

@MdSadiqMd
Copy link
Copy Markdown

Description

fixes #10054

This PR fixes an issue where Vitest was not preserving user-defined Vite resolve options when creating its test environment. Previously, custom resolve options like extensions, dedupe, preserveSymlinks, and options set by Vite plugins (such as vite-tsconfig-paths) were being discarded.

The root cause was that both VitestPlugin and WorkspaceVitestPlugin were creating a new resolve configuration that only included Vitest's default mainFields and conditions, completely ignoring viteConfig.resolve.

This fix introduces a mergeResolveOptions() helper function that:

  1. Preserves all user resolve options from the Vite config
  2. Overrides only mainFields and conditions with Vitest's required defaults (critical for test environment)
  3. Uses test alias if provided, otherwise preserves user's alias

This ensures that plugins like vite-tsconfig-paths work correctly in Vitest, and any custom resolve configuration is respected in tests while maintaining backward compatibility.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.
  • Added test/config/test/resolve-options.test.ts - Tests custom resolve options preservation
  • Added test/config/test/tsconfig-paths.test.ts - Tests alias resolution
  • All existing resolve-related tests pass (32 SSR resolve tests, core resolve tests)

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 7, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 9be0b63
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69d5fbf44e8e7d00087541f0
😎 Deploy Preview https://deploy-preview-10087--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
Copy link
Copy Markdown
Member

sheremet-va commented Apr 8, 2026

This PR fixes an issue where Vitest was not preserving user-defined Vite resolve options when creating its test environment. Previously, custom resolve options like extensions, dedupe, preserveSymlinks, and options set by Vite plugins (such as vite-tsconfig-paths) were being discarded.

This is not how config hook works. Vite accepts a partial config and merges it with user config. With this change, vite will merge the same config twice

Copy link
Copy Markdown
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't testing Vite 8's resolve: { tsconfigPaths: true } config.

@MdSadiqMd
Copy link
Copy Markdown
Author

#10054 (comment)

@hi-ogawa hi-ogawa closed this Apr 8, 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.

resolve.tsconfigPaths: true not applied in test environment (Vite 8)

3 participants