Skip to content

bundledDev + non-root base: dynamic import requests /@vite/lazy without base → 404 #23216

Description

@dark1451

Describe the bug

With experimental.bundledDev: true and a non-root base (e.g. /web-packages), dynamic import() in dev requests:

/@vite/lazy?id=...&clientId=...

instead of:

/web-packages/@vite/lazy?id=...&clientId=...

Because the path omits config.base, Vite's base middleware returns 404 ("did you mean /web-packages/@vite/lazy?...").

Expected: lazy proxy URL is prefixed with base.
Actual: hardcoded /@vite/lazy without base.

Notes:

  • Works with base: '/'
  • Works if the URL is manually rewritten to include /web-packages
  • Production (vite build + vite preview) under the same non-root base works — dev-only

Reproduction

https://stackblitz.com/github/dark1451/issue-vite-bundleddev-base-lazy?file=vite.config.ts

Steps to reproduce

  1. Open the reproduction (or clone + npm install + npm run dev)
  2. Open http://localhost:5173/web-packages/ (StackBlitz: open preview under /web-packages/)
  3. Open DevTools → Network → filter @vite/lazy
  4. Click "Load lazy module"
  5. Observe GET /@vite/lazy?... → 404
  6. Open the same URL with /web-packages inserted after the origin → 200
  7. Set base: '/' → dynamic import works
  8. npm run build && npm run preview with base: '/web-packages' → works

System Info

System:
    OS: macOS 15.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 189.64 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.21.1 - /Users/theo/.nvm/versions/node/v22.21.1/bin/node
    Yarn: 3.6.1 - /Users/theo/.nvm/versions/node/v22.21.1/bin/yarn
    npm: 10.9.4 - /Users/theo/.nvm/versions/node/v22.21.1/bin/npm
    pnpm: 10.9.0 - /Users/theo/.nvm/versions/node/v22.21.1/bin/pnpm
  Browsers:
    Chrome: 151.0.7922.108
    Safari: 18.3
  npmPackages:
    @vitejs/plugin-react: ^6.0.4 => 6.0.5 
    vite: ^8.2.0 => 8.2.1

Used Package Manager

npm

Logs

Click to expand!
# Network / terminal
GET /@vite/lazy?id=...&clientId=... → 404
# baseMiddleware suggests: /web-packages/@vite/lazy?...

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions