Skip to content

Virtual paths unexpectedly being rewritten #20803

Closed

Description

@marvinhagemeister

Describe the bug

When a resolveId hook returns a namespaced path with a null byte in front, it will be rewritten regardless of that.

\0http://example.com/virtual.js -> \0https:/example.com/virtual.js

Reproduction

https://stackblitz.com/edit/vitejs-vite-gq5fry2q?file=vite.config.ts,src%2Fmain.js,index.html&terminal=dev

Steps to reproduce

Visit the minimal reproduction case, error occurs when launching vite and visiting the dev server.

// vite.config.ts
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    {
      name: 'foo',
      resolveId(id) {
        if (id === 'virtual') {
          return `\0https://example.com/virtual.js`;
        }
      },
      load(id) {
        if (id === '\0https://example.com/virtual.js') {
          return `export default "ok";`;
        }
      },
    },
  ],
});

System Info

-

Used Package Manager

npm

Logs

Click to expand!
15:52:59 [vite] (client) Pre-transform error: Failed to load url https:/example.com/virtual.js (resolved id: https:/example.com/virtual.js) in /home/projects/vitejs-vite-gq5fry2q/src/main.js. Does the file exist?

Validations

Activity

  1. marvinhagemeister commented on Sep 19, 2025

    @marvinhagemeister
    ContributorAuthor

    Just checked with rollup and it doesn't rewrite the module id, so it's something in vite.

  2. added
    p2-edge-case
    on Sep 20, 2025
  3. locked and limited conversation to collaborators on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-case

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions