Skip to content

Reporter errors crash source-map formatting with Vite 8.3.5 (code.charCodeAt) #11682

Closed

Description

@juan-fernandez

Describe the bug

With Vitest 5.0.5 + Vite 8.3.5, formatting a custom reporter error crashes with:

TypeError: code.charCodeAt is not a function
    at extractInlineSourceMap
    at EvaluatedModules.getModuleSourceMapById

Expected: report the original reporter rejection error. This reproduces without dd-trace or other instrumentation.

Reproduction

Run in an empty directory with Node 26.2.0:

yarn init -y
yarn add --dev vitest@5.0.5 vite@8.3.5
cat > vitest.config.mjs <<'EOF'
export default { test: { include: ['test.mjs'], reporters: ['./reporter.mjs'] } }
EOF
cat > reporter.mjs <<'EOF'
export default class Reporter { onTestRunEnd () { throw new Error('reporter rejection') } }
EOF
cat > test.mjs <<'EOF'
import { test, expect } from 'vitest'
test('passes', () => expect(1).toBe(1))
EOF
node node_modules/vitest/vitest.mjs run

Investigation

ServerModuleRunner uses readFile(result.tmp), returning a Buffer where Vite expects source text. Changing it to readFile(result.tmp, 'utf-8') fixes the standalone reproduction. Vite 8.3.4 also avoids the crash in our integration tests.

System Info

macOS arm64; Node 26.2.0; Vitest 5.0.5; Vite 8.3.5.

Used Package Manager

yarn

Activity

  1. masonliiu commented on Oct 21, 2026

    @masonliiu

    Can confirm on Linux (Node 24) as well. The Buffer only started breaking with vitejs/vite#23775, which now calls code.charCodeAt on the fetched module, and the other result.tmp readers already pass 'utf-8', so the one call in serverRunner.ts is the only place that needs the change.

    I'm happy to open a PR with the fix and a regression test once this is approved, unless @juan-fernandez would like to send it since they found it.

  2. juan-fernandez commented on Oct 21, 2026

    @juan-fernandez
    ContributorAuthor

    unless maintainers approve the issue it's not possible to contribute a fix. I'm waiting for their approval 😄

  3. deadratfink commented on Oct 22, 2026

    @deadratfink

    Same root cause, different symptom, in case it helps triage: with vite 8.3.5 a globalSetup that imports aws-cdk-lib (stack trace capture) makes the whole run fail with TypeError: code.charCodeAt is not a function and "No test files found", so no test runs at all, not only the reporter output. In our run the modules with a Buffer as meta.code were exactly those that go through the result.tmp path (globalSetup and the CDK app files). Changing the call to readFile(result.tmp, "utf-8") fixes it: 252 files / 3196 tests pass with vitest 5.0.5 + vite 8.3.5; vite 8.3.4 is a workaround.

  4. added a commit that references this issue on Oct 22, 2026
    abd7c3b
  5. added
    p2-edge-case
    approved
    on Oct 22, 2026
  6. github-actions commented on Oct 22, 2026

    @github-actions

    This issue is approved, so the team accepts a pull request for it. To work on it, open a pull request against main and link this issue in its description with a closing keyword, for example Fixes #11682.

    The team accepts one pull request per issue: if another pull request for this issue is already open, a new one is closed automatically. See our pull request policy for more context.

  7. added a commit that references this issue on Oct 24, 2026
    867a5e4
  8. added a commit that references this issue on Oct 30, 2026
  9. locked and limited conversation to collaborators on Nov 8, 2026
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

    approvedp2-edge-case

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions