Skip to content

CSS url() regression in Vite 8 when base is set to ./ #22434

@karlvr

Description

@karlvr

Describe the bug

When base: './' is set and the build is configured to emit CSS into a subfolder (via assetFileNames) while keeping images in a sibling folder,
Vite 8 writes url(./img/...) into the CSS instead of url(../img/...), which Vite 7 writes.

Reproduction

https://github.com/karlvr/vite-relative-base-bug

Steps to reproduce

npm install
npm run build:v8

Inspect ./dist/css/main-*.css and observe that the url to the background image is incorrect. It should be ../img/foo-*.png but it's ./img/foo-*.png.

You can compare with Vite 7 by running:

npm run build:v7

System Info

System:
    OS: macOS 15.7.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 119.17 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.15.0 - /Users/karlvr/.local/share/mise/installs/node/24/bin/node
    npm: 11.12.1 - /Users/karlvr/.local/share/mise/installs/node/24/bin/npm
    pnpm: 11.0.8 - /Users/karlvr/.local/share/mise/installs/node/24/bin/pnpm
    Watchman: 2026.05.04.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 147.0.7727.138
    Firefox: 59.0.3
    Safari: 26.4

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: cssp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions