Skip to content

resolve.tsconfigPaths: path aliases fail to resolve when importer is a virtual module with project references #21889

Closed

Description

@Wassim24

Describe the bug

When resolve.tsconfigPaths: true is used and tsconfig.json contains references, path aliases fail to resolve when the importer is a virtual module (i.e., its module ID contains a query string, such as file.tsx?tsr-split=component generated by TanStack Router).

The resolution works correctly when:

  • The importer is a regular file (no query string)
  • All compiler options (including paths) are merged into the root tsconfig.json with no references
  • The paths are duplicated directly in the root tsconfig.json alongside the references

It fails when:

  • tsconfig.json has references pointing to other configs
  • The paths are defined in a referenced tsconfig (e.g., tsconfig.app.json)
  • The importer is a virtual module with a query string in its ID for example

This was confirmed by additional testing:

  • Moving all content from tsconfig.app.json into tsconfig.json (eliminating references) fixes the issue
  • Adding paths directly to root tsconfig.json alongside references also works — because Vite finds paths in root directly without needing to delegate to a referenced config.
  • Disabling TanStack Router's autoCodeSplitting also fixes the issue — because no virtual modules with query strings are generated, all importers are regular files, and path resolution works normally.

It looks to me, that the bug is exclusively triggered by virtual module importers (files with a query string in their ID).

Reproduction

Here is a reproduction repo : https://stackblitz.com/edit/vitejs-vite-zbpvcavb?file=src%2FApp.tsx

Steps to reproduce on your side :

  1. Create a Vite 8 + React + TypeScript project with the default project references setup

tsconfig.app.json (paths defined here, NOT in root):

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"]
    }
  },
  "include": ["src"]
}

vite.config.ts:

import tanstackRouter from "@tanstack/router-plugin/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
  // I use tanstack router because I encountred the issue with it.
  plugins: [tanstackRouter(), react()],
  resolve: { tsconfigPaths: true },
});
  1. Use a path alias inside a route file (TanStack Router splits route files into virtual modules with ?tsr-split=component in the ID):
// src/routes/index.tsx
import MyComponent from "@components/MyComponent.tsx";
  1. Run vite dev or vite build.

Expected: @components/MyComponent.tsx resolves correctly.

Actual:

Rolldown failed to resolve import "@atoms/Button.tsx" from "/home/projects/vitejs-vite-zbpvcavb/src/routes/index.tsx?tsr-split=component".
This is most likely unintended because it can break your application at runtime.

The error always originates from a module ID containing a query string. Imports from regular files (without query strings) resolve correctly.

Workaround: See above when resolution works correctly.

System Info

System:
    OS: macOS 26.3
    CPU: (11) arm64 Apple M3 Pro
    Memory: 87.88 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.13.0 - /home/.local/share/mise/installs/node/24.13.0/bin/node
    npm: 11.6.2 - /home/.local/share/mise/installs/node/24.13.0/bin/npm
    pnpm: 10.19.0 - /home/.local/share/mise/installs/node/24.13.0/bin/pnpm
    Watchman: 2026.03.09.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 144.0.7559.60
    Safari: 26.3
  npmPackages:
    @vitejs/plugin-react: ^6.0.1 => 6.0.1
    vite: ^8.0.0 => 8.0.0

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guidelines
  • Read the docs
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate
  • Make sure this is a Vite issue and not a framework-specific issue
  • Check that this is a concrete bug
  • The provided reproduction is a minimal reproducible example of the bug

Activity

  1. psychobolt commented on Mar 17, 2026

    @psychobolt
    Contributor

    Some good use cases here. I originally left my issue comment in the rolldown project in case it's a upstream issue: rolldown/rolldown#8468 (comment)

  2. yetdragon commented on Mar 21, 2026

    @yetdragon

    Related case:

    Using Vite 8, Svelte, and vite-plugin-svelte 7 with the following tsconfig.json:

    {
    	"compilerOptions": {
    		"paths": {
    			"$lib": ["./src/lib"],
    			"$lib/*": ["./src/lib/*"]
    		}
    	}
    }

    and if you import a Svelte component with a <style> block via the tsconfig path alias:

    <!-- App.svelte -->
    <script>
    	import Something from "$lib/Something.svelte"
    </script>
    <!-- src/lib/Something.svelte -->
    <div></div>
    
    <style>
    	div { color: red; }
    </style>

    vite build fails with cryptic error, because the JS import resolves correctly, but the virtual CSS module that vite-plugin-svelte generates fails to load. lightningcss then receives the raw .svelte source instead of compiled CSS:

    error during build:
    Build failed with 1 error:
    
    [plugin vite:css-post]
    SyntaxError: [lightningcss minify] Invalid empty selector
    1  |  <div></div>
       |  ^
    2  |
    ...
    

    I see that, from #6828, relying on tsconfig.json for path aliasing is an anti-pattern, but I believe the error action should be more concrete than failing mysteriously.

  3. added
    bug: upstream
    p3-downstream-blocker
    on Mar 23, 2026
  4. sapphi-red commented on Mar 23, 2026

    @sapphi-red
    Member

    This will be fixed by oxc-project/oxc-resolver#1081.

  5. self-assigned this
    on Mar 23, 2026
  6. Wassim24 commented on Mar 25, 2026

    @Wassim24
    Author

    Thank you @sapphi-red, this is great news !

  7. chaotic-justice commented on Apr 27, 2026

    @chaotic-justice

    sharing a tanstack cf worker case which also build fails:

    import { cloudflare } from "@cloudflare/vite-plugin";
    import tailwindcss from "@tailwindcss/vite";
    import { devtools } from "@tanstack/devtools-vite";
    import { tanstackStart } from "@tanstack/react-start/plugin/vite";
    import viteReact from "@vitejs/plugin-react";
    import { defineConfig } from "vitest/config";
    
    const config = defineConfig({
    	resolve: {
    		tsconfigPaths: true,
    		dedupe: ["react", "react-dom"],
    	},
    	plugins: [...]
    });
    
    export default config;
    {
    	"extends": "@repo/typescript-config/vite-app.json",
    	"compilerOptions": {
    		"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    		"incremental": true,
    		"types": ["./worker-configuration.d.ts", "node", "vite/client"],
    		"baseUrl": ".",
    		"paths": {
    			"@/*": ["./src/*"],
    			"@monoshop/core": ["../../packages/core/src"],
    			"@monoshop/ui": ["../../packages/ui/src"],
    			"~ui/*": ["../../packages/ui/src/*"]
    		}
    	},
    	"include": ["src"],
    	"exclude": ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx"]
    }
    ✗ Build failed in 4.15s
    error during build:
    Build failed with 1 error:
    Error: [vite]: Rolldown failed to resolve import "@/components/footer" from "/home/runner/work/bun-monoshop/bun-monoshop/apps/web/src/routes/_main.tsx?tsr-split=component".
    
  8. bennylii commented on May 1, 2026

    @bennylii

    I can confirm this also affects Windows + Vue SFC with the same root cause.

    On Windows 10, vite dev fails at the dependency scan phase when importing from @/ aliases inside a .vue file. Vue SFCs get a query string appended to their module ID (e.g., App.vue?id=0), making them virtual modules just like the TanStack Router case.

    Error:

    Failed to run dependency scan. Skipping dependency pre-bundling. Error:
    The following dependencies are imported but could not be resolved:
    
      @/util/foo (imported by C:/Users/.../src/App.vue?id=0)
    

    Minimal repro (same pattern, different trigger — Vue instead of TanStack Router):
    https://github.com/bennylii/vite-tsconfig-repro

    Affected versions: Vite 8.0.0 through 8.0.10 (all tested).

    Note: vite build works fine on Windows in this scenario — only vite dev is affected. That differs slightly from the TanStack Router case where build also fails.

  9. mkarajohn commented on May 8, 2026

    @mkarajohn

    We have the exact same issue with a tanstack router application, and it's a blocker for vite 8 adoption, right now.

    the error we get:

    ✗ Build failed in 1.52s
    error during build:
    Build failed with 1 error:
    
    
    Error: [vite]: Rolldown failed to resolve import "<component>.tsx" from "<.....>index.tsx?tsr-split=component".
    This is most likely unintended because it can break your application at runtime.
    If you do want to externalize this module explicitly add it to
    `build.rollupOptions.external`
    

    The sometimes is different between failed build attempts

  10. linked a pull request that will close this issuefeat: update rolldown to 1.1.1 #22593on Jun 9, 2026
  11. locked and limited conversation to collaborators on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug: upstreamclarity: highp3-downstream-blocker

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions