Skip to content

browser: @vite/client cannot load when a custom base is set #6509

@nstepien

Description

@nstepien

Describe the bug

When a custom base is set in the vite config, browser tests fail to load /custom-base/@vite/client.
This error doesn't show up in the cli, but it does show up in the browser's console.
It doesn't seem to affect tests though, afaict.

image

Setting '/' for tests only fixes the issue.

const isTest = process.env.NODE_ENV === 'test';

export default defineConfig({
  base: isTest ? '/' : '/custom-base/',

Reproduction

export default defineConfig({
  base: '/custom-base/',
  // ...
  test: {
    browser: {
      enabled: true,
      name: 'chromium',
      provider: 'playwright',
      headless: false
    }
  }
});

Not minimal, but you can also reproduce with this repo:
https://github.com/adazzle/react-data-grid/blob/main/vite.config.ts#L11

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (64) x64 AMD Ryzen Threadripper 3970X 32-Core Processor
    Memory: 16.97 GB / 31.88 GB
  Binaries:
    Node: 22.8.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1
    @vitest/browser: ^2.1.1 => 2.1.1
    @vitest/coverage-v8: ^2.1.1 => 2.1.1
    @vitest/eslint-plugin: ^1.1.4 => 1.1.4
    vite: ^5.4.5 => 5.4.5
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions