Skip to content

The following Vite config options will be overridden by SvelteKit: root #13376

Description

@rChaoz

Describe the bug

This warning pops up when running vitest on Windows. It seems like the config() function of the Kit Vite plugin runs multiple times, and that paths are normalized (possibly since Vite 6?). The warning comes from this line:

if (config[key] !== resolved_config[key]) {

where, for me, the configs have these values:

  • config.root = C:/Users/.../project-dir
  • resolved_config.root = C:\Users\...\project-dir

So, the 2 configs have the same path, but one with forward slashes, and one with backslashes.
SvelteKit itself tries to set config.root to the version with backslashes, as it uses process.cwd() to get it. Maybe it should use posixify() on it before? Replacing this line:

with this:

	root: posixify(cwd),

Activity

  1. damiensawyer commented on Apr 13, 2025

    @damiensawyer

    If anyone is interested, I got AI to write a patch script to help with this until it's fixed.

    Added this to package.json
    "scripts": {
    "postinstall": "node ./scripts/patch-script.js"
    }

    and created this file.

    #!/usr/bin/env node
    
    // This will be deleted when Svelte releases this fix https://github.com/sveltejs/kit/issues/13376
    
    import fs from 'fs';
    import path from 'path';
    import { fileURLToPath } from 'url';
    
    // Get current directory
    const __filename = fileURLToPath(import.meta.url);
    const __dirname = path.dirname(__filename);
    
    // Path to the file we need to modify
    const filePath = path.join(
      process.cwd(),
      'node_modules',
      '@sveltejs',
      'kit',
      'src',
      'exports',
      'vite',
      'index.js'
    );
    
    console.log(`Checking for SvelteKit file at: ${filePath}`);
    
    // Check if the file exists
    if (!fs.existsSync(filePath)) {
      console.log('SvelteKit file not found. The patch was not applied.');
      process.exit(0);
    }
    
    // Read the file
    let content = fs.readFileSync(filePath, 'utf8');
    
    // Look for the line we need to change
    const searchString = 'root: cwd,';
    const replaceString = 'root: posixify(cwd),';
    
    // Check if the file already contains the fix
    if (content.includes(replaceString)) {
      console.log('The SvelteKit file is already patched.');
      process.exit(0);
    }
    
    // Check if the line to change exists
    if (!content.includes(searchString)) {
      console.log('The line to patch was not found. Structure may have changed. Please check manually.');
      process.exit(1);
    }
    
    // Apply the change
    const patchedContent = content.replace(searchString, replaceString);
    
    // Write the file back
    fs.writeFileSync(filePath, patchedContent, 'utf8');
    
    console.log('Successfully patched SvelteKit vite/index.js to use posixify(cwd).');
  2. rebasecase commented on Aug 12, 2025

    @rebasecase
  3. niemyjski commented on Sep 21, 2025

    @niemyjski

    I'm also seeing this with storybook

  4. tylergannon commented on Oct 25, 2025

    @tylergannon

    macOS too with latest tooling.

    package.json

  5. thunze commented on Oct 31, 2025

    @thunze

    Seeing

    The following Vite config options will be overridden by SvelteKit:
      - base
    

    since upgrading to Vitest 4. Possibly related.

  6. peterpeterparker commented on Nov 21, 2025

    @peterpeterparker

    The following Vite config options will be overridden by SvelteKit:

    • base

    - base is popping as well in my projects when I migrate from vitest v3 to v4.

  7. huangsam commented on Nov 26, 2025

    @huangsam

    Seeing

    The following Vite config options will be overridden by SvelteKit:
      - base
    

    since upgrading to Vitest 5. Possibly related.

    Looking into this issue, it appears that Vitest >=4 sets the base path to '/' by default, which is not acceptable according to the SvelteKit docs which say:

    A root-relative path that must start, but not end with / (e.g. /base-path), unless it is the empty string...

    I realized this by simply appending these lines right after the console.error from the warn_overridden_config API:

    console.info("config", `'${config.base}'`); // Shows '/'
    console.info("resolved_config", `'${resolved_config.base}'`); // Shows ''

    I foresee a few options, in case that helps future maintainers or users who stumble upon this issue:

    • Wait for SvelteKit team to address the initial assumptions around Vitest
    • File a PR to refine the underlying assumptions around Vitest
    • Reach out to Vitest team regarding their breaking changes
    • Apply a local hack to the SvelteKit logic so that it suppresses that warning only for the base key
    • Keep vitest under 4.x for our specific projects
  8. lewisacidic commented on Dec 16, 2025

    @lewisacidic

    An simple hack for the base issue is to reset base to '' in a plugin that runs before sveltekit. A super minimal vite.config.ts might look like:

    import { defineConfig } from 'vitest/config'
    import { sveltekit } from '@sveltejs/kit/vite'
    
    export default defineConfig({
      plugins: [
        // fix for vitest v4 setting base to '/'
        {
          name: 'reset-base',
          config() {
            return {
              base: '',
            }
          },
        },
        sveltekit(),
      ],
      test: {
        name: 'server',
        environment: 'node',
        include: ['src/**/*.{test,spec}.{js,ts}'],
      },
    })
    

    This stops the annoying bold red message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions