Skip to content

@uiw/codemirror-theme-* crashes vitest workers when --coverage is enabled #765

@trivedi

Description

@trivedi

Problem

Tests pass without --coverage but fail when coverage is enabled, with errors like:

  Error: Cannot find package '@lezer/highlight' imported from                                                                                                           
    .../node_modules/.pnpm/@uiw+codemirror-theme-github@.../node_modules/@uiw/codemirror-theme-github/...

Unrelated test files also fail because vitest runs multiple test files per worker — one package load failure crashes the whole worker.

Root Cause

@uiw/codemirror-theme-* packages import @lezer/highlight internally but don't declare it as a dependency in their package.json. This is a bug in those upstream
packages.

Why it only fails with --coverage:

  • Without --coverage: Vite bundles the theme packages through its own resolver, which searches broadly across the workspace and finds @lezer/highlight in
    packages/app/node_modules. No error.
  • With --coverage: vitest's v8 coverage provider loads node_modules packages via Node's native ESM loader for instrumentation, bypassing Vite's resolver
    entirely. Node follows pnpm's strict isolation rules — a package can only resolve its declared dependencies — so @lezer/highlight is not found.

Why npm/yarn users don't hit this: Both use a flat node_modules layout where any package can access anything installed. pnpm's virtual store enforces
declared-dependency isolation.

Workaround

Add packageExtensions entries in pnpm-workspace.yaml for each affected theme package, declaring @lezer/highlight as a dependency:

packageExtensions:
  "@uiw/codemirror-theme-github@*":
    dependencies:                                                                                                                                                     
      "@lezer/highlight": "*"
  "@uiw/codemirror-theme-vscode@*":                                                                                                                                   
    dependencies:
      "@lezer/highlight": "*"
  # ... other @uiw/codemirror-theme-* packages
                                                                                                                                                                      
pnpm then symlinks @lezer/highlight into each theme package's virtual store node_modules, making it available regardless of loader — Vite, Node, or the v8 coverage
provider.                                                                                                                                                             

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions