Skip to content

TypeError: Cannot read properties of undefined (reading 'endCol') #6297

Description

@stramel

Describe the bug

Appears to be a regression of a previous bug: #5639
Related PR for previous bug: #5642

When running coverage using @vitest/coverage-v8, with CJS files, it fails to properly report coverage.

As noted in the previous issue, adding a comment above the export makes the coverage work.

npm run cover

> cover
> vitest run --coverage


 RUN  v2.0.5 /Users/mstramel/PayPal/vitest-v8-coverage-repro
      Coverage enabled with v8

 ✓ test/basic.test.js (1)
   ✓ levels (1)
     ✓ should pass

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
TypeError: Cannot read properties of undefined (reading 'endCol')
 ❯ range.sliceRange node_modules/@vitest/coverage-v8/dist/provider.js:423:55
 ❯ CovSource.offsetToOriginalRelative node_modules/@vitest/coverage-v8/dist/provider.js:1584:20
 ❯ V8ToIstanbul._maybeRemapStartColEndCol node_modules/@vitest/coverage-v8/dist/provider.js:1987:92
 ❯ node_modules/@vitest/coverage-v8/dist/provider.js:1896:60
 ❯ node_modules/@vitest/coverage-v8/dist/provider.js:1894:20
 ❯ V8ToIstanbul.applyCoverage node_modules/@vitest/coverage-v8/dist/provider.js:1893:12
 ❯ node_modules/@vitest/coverage-v8/dist/provider.js:2609:21




 ✓ test/basic.test.js (1)
   ✓ levels (1)
     ✓ should pass
close timed out after 10000ms
Tests closed successfully but something prevents Vite server from exiting
You can try to identify the cause by enabling "hanging-process" reporter. See https://vitest.dev/config/#reporters

Reproduction

Reproduction on GitHub because StackBlitz doesn't support @vitest/coverage-v8.

Minimal Reproduction: https://github.com/stramel/vitest-v8-coverage-repro/tree/main

Steps:

  • Run npm run cover
  • Observe error

Expected Result: Coverage should finish correctly without error
Actual Result: Coverage doesn't finish and results in the error TypeError: Cannot read properties of undefined (reading 'endCol')

If you change src/basic.js to this

"use strict";

// FIX ISSUE

module.exports = {
  debug: 0,
  info: 1,
  warn: 2,
  error: 3,
  fatal: 4,
};

then run npm run cover it will work as expected.

System Info

`npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers`


  System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Max
    Memory: 151.23 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.20.4 - ~/.volta/tools/image/node/18.20.4/bin/node
    Yarn: 1.22.19 - ~/.volta/bin/yarn
    npm: 10.8.2 - ~/.volta/tools/image/npm/10.8.2/bin/npm
  Browsers:
    Chrome: 127.0.6533.73
    Chrome Canary: 123.0.6270.0
    Edge: 127.0.2651.86
    Safari: 17.5
  npmPackages:
    @vitest/coverage-v8: latest => 2.0.5
    @vitest/ui: latest => 2.0.5
    vite: latest => 5.3.5
    vitest: latest => 2.0.5

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage featurep2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions