Skip to content

Vitest 4.x internal typescript error with Vite <=7.1.0 #9055

@simon-abbott

Description

@simon-abbott

Describe the bug

Vitest 4.x lists "vite": "^6.0.0 || ^7.0.0" as a dependency, but if you use any version of vite before v7.1.0, TypeScript errors with:

node_modules/vitest/dist/chunks/moduleRunner.d.BxT-OjLR.d.ts:174:74 - error TS2339: Property 'createImportMeta' does not exist on type 'ModuleRunnerOptions'.

174 type CreateImportMeta = NonNullable<viteModuleRunner.ModuleRunnerOptions["createImportMeta"]>;
                                                                             ~~~~~~~~~~~~~~~~~~

Note that this only happens if the vitest.config.ts file is included in the TypeScript context.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-lew46gxc?file=tsconfig.json

System Info

System:
    OS: macOS 15.7.2
    CPU: (14) arm64 Apple M4 Pro
    Memory: 524.47 MB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.11.1 - /Users/<redacted>/.nvm/versions/node/v24.11.1/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 11.6.2 - /Users/<redacted>/.nvm/versions/node/v24.11.1/bin/npm
    Watchman: 2025.04.21.00 - /run/current-system/sw/bin/watchman
  Browsers:
    Firefox: 145.0
    Firefox Developer Edition: 145.0
    Safari: 26.1
  npmPackages:
    vite: 7.0.4 => 7.0.4 
    vitest: 4.0.10 => 4.0.10

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions