Skip to content

Vitest >=4 throws error cannot find package '__sveltekit' in SvelteKit project #8826

@danieldiekmeier

Description

@danieldiekmeier

Describe the bug

After updating to vitest 4.0.3, I can't run my tests anymore. Instead, I get this error:

Error: Cannot find package '__sveltekit' imported from /home/projects/vitest-dev-vitest-u8f2u2kl/node_modules/@sveltejs/kit/src/runtime/app/environment/index.js

This happens when I try to import any special SvelteKit module that's prefixed with $, like $app/environment.

There have been similar issues in the past, like #3483 and #4067.

Reproduction

StackBlitz: https://stackblitz.com/edit/vitest-dev-vitest-u8f2u2kl?file=src%2Fdoes-not-work.svelte.js

Run npm test. The default output is very cut off in StackBlitz, that's why I configured it to use the tap reporter instead.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 4.0.3 
    vite: latest => 7.1.12 
    vitest: latest => 4.0.3 

(These are the values from StackBlitz)

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p4-importantViolate documented behavior or significantly improves performance (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions