sveltejs / sveltejs/kit

[vite-plugin-svelte:load] failed to load virtual css module

Open
#14,490 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

paths.base vite
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the bug

When setting up a new SvelteKit project, you may encounter a failure in development mode if the project’s location folder matches the kit.paths.base configuration setting. Specifically, you cannot place your project in a directory like /home/user and configure kit.paths.base with a prefix such as '/home'. This conflict arises due to how SvelteKit resolves paths internally, leading to issues during the development server startup.

Reproduction

my-app.tar.gz

cd /tmp
tar zxf my-app.tar.gz
cd my-app/
npm install
npm run dev

From another terminal run
curl http://localhost:5173/tmp/
[...]

                <div class="error">
                        <span class="status">500</span>
                        <div class="message">
                                <h1>Internal Error</h1>
                        </div>
                </div>
Logs
> my-app@0.0.1 dev
> vite dev

4:21:39 PM [vite] (client) Forced re-optimization of dependencies

  VITE v7.1.6  ready in 469 ms

  ➜  Local:   http://localhost:5173/tmp
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
4:21:56 PM [vite-plugin-svelte:load] failed to load virtual css module /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css
4:21:56 PM [vite] (ssr) Error when evaluating SSR module /src/routes/+layout.svelte: Failed to load url /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css (resolved id: /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css) in /tmp/my-app/src/routes/+layout.svelte. Does the file exist?
      at loadAndTransform (file:///tmp/my-app/node_modules/vite/dist/node/chunks/dep-D5b0Zz6C.js:26109:33)

[500] GET /tmp/
Error: Failed to load url /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css (resolved id: /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css) in /tmp/my-app/src/routes/+layout.svelte. Does the file exist?
    at loadAndTransform (file:///tmp/my-app/node_modules/vite/dist/node/chunks/dep-D5b0Zz6C.js:26109:33)

[500] GET /tmp/
Error: Failed to load url /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css (resolved id: /my-app/src/routes/+layout.svelte?svelte&type=style&lang.css) in /tmp/my-app/src/routes/+layout.svelte. Does the file exist?
    at loadAndTransform (file:///tmp/my-app/node_modules/vite/dist/node/chunks/dep-D5b0Zz6C.js:26109:33)
System Info
System:
    OS: Linux 6.14 Ubuntu 25.04 25.04 (Plucky Puffin)
    CPU: (6) x64 Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz
    Memory: 27.09 GB / 31.09 GB
    Container: Yes
    Shell: 5.2.37 - /bin/bash
  Binaries:
    Node: 20.19.5 - /usr/bin/node
    npm: 11.6.0 - /usr/bin/npm
    pnpm: 10.17.0 - ~/.local/share/pnpm/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.0 
    @sveltejs/kit: ^2.22.0 => 2.42.2 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.2.0 
    svelte: ^5.0.0 => 5.39.3 
    vite: ^7.0.4 => 7.1.6
Severity

serious, but I can work around it

Additional Information

To make it working either change location folder or kit.paths.base in svelte.config.js

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the provided archive and the npm install, npm run dev, and curl commands. Start by checking svelte.config.js and the vite-plugin-svelte load error involving the virtual CSS module; done means the development server handles a project location matching kit.paths.base without the 500 response.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, vite
Domain
tooling, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.