Skip to content

fix(vite-plugin-vue,vite-plugin-solid): resolve relative .tsrx imports from a module Vitest loads by URL - #1250

Merged
jonkwheeler merged 2 commits into
tsrx-org:mainfrom
jonkwheeler:fix/vite-relative-tsrx-imports
Nov 12, 2026
Merged

jonkwheeler merged 2 commits into
tsrx-org:mainfrom
jonkwheeler:fix/vite-relative-tsrx-imports

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Under Vitest, a .tsrx test file can import another .tsrx file by a relative path (#1247). Before, with @tsrx/vite-plugin-vue or @tsrx/vite-plugin-solid, import { Parent } from './fixtures/parent.tsrx' in a .test.tsrx file failed with ENOENT: no such file or directory, open '<root>/fixtures/parent.tsrx'. The React and Preact plugins already worked.

Vitest asks for the test module by its root-relative URL (/packages/vite-plugin-vue/tests/App.test.tsrx.tsx). resolveId kept a virtual .tsrx.tsx id as written whenever it looked absolute, so that URL became the module's id. load re-anchored it to find the file, but imports from the module resolved against a path that doesn't exist, so a relative import ended up at the root. resolveId now anchors such an id to the file under the root, the way load already finds it, and spells it the way Vite's resolver does: the anchored path goes through this.resolve, which applies Vite's symlink rules, and then through normalizePath. So a file reached through a symlinked root (/tmp on macOS) has the same module id whether it's reached by URL or by import. An id that needs no anchoring stays as it is. The change sits at the start of resolveId; #1101 changes its end, and the two merge without conflicts.

This turned out to be in the published plugins, not only the repo's test setup: any project that runs Vitest with these plugins hits it. So the PR changes plugin code and has a patch changeset.

Verification

  • New runtime test files relative-imports.test.tsrx in the Vue and Solid runtime projects import ./fixtures/relative-imports/parent.tsrx, which imports ./child.tsrx, and render it. Both failed with the ENOENT above and pass now.
  • Plugin unit tests: resolveId('/tests/App.test.tsrx.tsx') returns <root>/tests/App.test.tsrx.tsx, and an absolute virtual id is kept. Both failed before.
  • With a real Vite dev server whose root is a symlink, resolving /tests/App.test.tsrx.tsx by URL gives the real path, the same id as importing ./tests/App.test.tsrx. This failed before the second commit, which returned the symlink spelling.
  • The Vite plugin and runtime projects for Vue, Solid and React pass (511 tests).
  • Full npx vitest run: 10015 passed, 0 failed.
  • pnpm typecheck clean, pnpm changeset:check passes, Prettier clean on changed files.

Related

Fixes #1247
Related: #1200, #1229 (their runtime fixture lives in the shared harness directory because of this), #1101

🤖 Generated with Claude Code


Note

Medium Risk
Changes core module resolution in published Vite plugins; behavior is narrow (virtual .tsrx.tsx ids under Vitest) but incorrect anchoring could break imports or duplicate module instances.

Overview
Fixes Vitest failures when a .test.tsrx file uses a relative import to another .tsrx file with @tsrx/vite-plugin-vue or @tsrx/vite-plugin-solid. Vitest loads the test by a root-relative URL (e.g. /tests/App.test.tsrx.tsx); resolveId used to keep that URL as the module id, so nested relative imports resolved from the project root and hit ENOENT.

resolveId now re-anchors virtual .tsrx.tsx ids to the on-disk file, using the same toRealPath / to_real_path logic as load, this.resolve, and Vite's normalizePath, so one stable id is used whether the module is reached by URL or by a normal import (including through a symlinked project root).

Both plugins get unit tests for root-relative and symlink id spelling, plus .tsrx integration tests that import a parent fixture which imports a child. A patch changeset covers both packages.

Reviewed by Cursor Bugbot for commit 847266c. Bugbot is set up for automated code reviews on this repo. Configure here.

…l id

Vitest asks for a test module by its root-relative URL, such as
`/packages/vite-plugin-vue/tests/App.test.tsrx.tsx`. resolveId kept a
virtual id as written whenever it looked absolute, so that URL became
the module's id. `load` re-anchored it to find the file, but imports
from the module resolved against a path that doesn't exist, and a
relative `.tsrx` import ended up at the project root (ENOENT).

resolveId now anchors a virtual id the way `load` already does. An id
that is already the real file's path, and one that can't be found under
the root, stay as they were.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…does

The previous commit anchored a root-relative virtual id to the file
under the root as written. Through a symlinked root (`/tmp` on macOS,
say) that kept the symlink spelling, while an import of the same file
resolves to its real path, so one file could get two module ids.

Resolve the anchored path through Vite's resolver instead, which applies
its own symlink rules, and run the id through `normalizePath` for `/`
separators on Windows. An id that needs no anchoring stays as it was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jonkwheeler
jonkwheeler marked this pull request as ready for review October 29, 2026 13:08
@jonkwheeler
jonkwheeler merged commit b706778 into tsrx-org:main Nov 12, 2026
8 checks passed
jonkwheeler added a commit to jonkwheeler/tsrx that referenced this pull request Nov 12, 2026
Main's tsrx-org#1091 added resolveTsconfigJsx (source, types and tests) where this branch adds getBuildPlatformConfigFiles, and tsrx-org#1250 added a normalizePath import from vite in the Solid and Vue plugins where this branch imports parseSync; both sides are kept in each file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
jonkwheeler added a commit that referenced this pull request Nov 12, 2026
The Solid and Vue plugin tests keep main's #1250 module-id tests and this branch's HMR CSS test, with both sides' node:fs imports. Main's #1125 already keeps the binding of a default-exported Vue component (const App = ...; export default App), so main's transform and shared compile test are kept, this branch's equivalent export-specifier rewrite and its vue-default-function-export changeset are dropped, and its Vue regression test, which passes on main's output, is kept.

pnpm-lock.yaml is main's plus the entries this branch's lockfile added, re-resolved with the storybook-examples vue and vue-jsx-vapor pins moved to main's 3.6.0-rc.14 and 3.2.29 (#1296), so the README and llms.txt no longer list a Vue peer mismatch. Starting from main's lockfile alone resolved vue-component-meta 3.3.14, which brings @volar/* 2.4.30 and gives the VS Code extension two volar-service-typescript copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRKmwAwuyPbGQ1ejNqiJ46
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.

[Bug]: vite-plugin-vue, vite-plugin-solid: under Vitest, a relative .tsrx import from a .tsrx test file resolves against the project root

1 participant