Skip to content

vitest should declare @vitest/coverage-v8 and @vitest/coverage-istanbul as optional peer dependencies #10015

Description

@baraknaveh

vitest@4.1.1 dynamically imports @vitest/coverage-v8 when coverage.provider is set to "v8":

Error: Cannot find package '@vitest/coverage-v8' imported from .../node_modules/vitest/dist/chunks/coverage.CTzCuANN.js

This works in hoisted node_modules layouts (npm, yarn) because @vitest/coverage-v8 is hoisted from the consuming project. In pnpm's strict isolation (default in pnpm 10), vitest can only resolve packages declared in its own dependency tree — and since @vitest/coverage-v8 isn't listed as a peer, pnpm doesn't link it.

vitest already declares optional peers for @vitest/browser-* and @vitest/ui. Adding coverage providers would be consistent with that pattern.

Temp workaround:

# pnpm-workspace.yaml
packageExtensions:
  "vitest@4":
    peerDependencies:
      "@vitest/coverage-v8": "*"
    peerDependenciesMeta:
      "@vitest/coverage-v8":
        optional: true

Suggested proper fix:

Add @vitest/coverage-v8 and @vitest/coverage-istanbul as optional peer dependencies in vitest's package.json, matching the existing pattern for @vitest/browser-* and @vitest/ui.

Why is it important?

The import failure happens in runtime, so it can silently break things for people who adopting strict isolation (no hoisting).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions