Skip to content

Web environments can't import a module whose path contains a colon (Vite 8.0.16+) #11413

Description

@ragulka

Describe the bug

Since Vite 8.0.16 (also 7.3.5 and 6.4.3), a test in jsdom or happy-dom can't import a module whose path contains a colon:

Error: Cannot find module '/src/route:name/index.ts' imported from <root>/test/jsdom.test.ts

The same import works in node, and it works in the browser through Vite's dev server.

I ran into this with Laravel Wayfinder, which names route directories after route names (routes/company:logo/index.ts). Our tests passed on Vitest 2, which bundles Vite 5.4. After upgrading to Vitest 5, every component test that imports such a route failed.

From what I can tell, the cause is vitejs/vite#22572 (GHSA-fx2h-pf6j-xcff). It made isFileLoadingAllowed reject any path that contains : while server.fs.strict is on. The dev server still loads static imports, because import analysis pre-transforms them with warmupRequest, which skips the check. Vitest sets preTransformRequests = false, so each fetch in the client environment runs the check. The ssr environment skips it, which is why node passes.

For now I work around it with server.fs.strict: false when running under Vitest. I'd like to send a PR with a fix.

I used Claude Code to help track this down and write it up.

Reproduction

https://github.com/ragulka/vitest-colon-path-repro

pnpm install
pnpm test

test/node.test.ts passes. test/jsdom.test.ts and test/happy-dom.test.ts fail.

System Info

  System:
    OS: macOS 27.0.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 213.03 MB / 64.00 GB
    Shell: 5.9
  Binaries:
    Node: 22.22.2
    Yarn: 1.22.19
    npm: 10.9.7
    pnpm: 10.33.4
    Deno: 2.7.1
  Browsers:
    Brave Browser: 153.1.95.101
    Chrome: 154.0.8037.92
    Firefox: 123.0.1
    Firefox Developer Edition: 153.0
    Safari: 27.0.1
  npmPackages:
    vite: 8.2.1 => 8.2.1
    vitest: 5.0.3 => 5.0.3

Used Package Manager

pnpm

Validations

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions