Crash in code highlighting: undefined is not a constructor (v2.0.71)

Status Fixed / completed
Maintainer reply None cached
Activity 5 comments · opened Dec 17, 2025 · closed Dec 18, 2025

Bug Description

Claude Code crashes with a JavaScript error when attempting to render syntax-highlighted code blocks.

Error Message

ERROR  undefined is not a constructor (evaluating 'new U($,A)')

/$bunfs/root/claude:1137:5029

Environment

  • Version: Claude Code v2.0.71
  • Platform: Linux 4.18.0-553.51.1.el8_10.cloud.0.1.x86_64
  • Model: Sonnet 4.5
  • Working Directory: /proj/a1/fe/rajc/a1_latest

Root Cause Analysis

Based on the crash stack trace, the issue occurs in the code highlighting component around line 1137:

M=gz.useMemo(()=>{let U=q4I();if(U===null)return null;return new U($,A)},[$,A]);

The problem:

  1. q4I() returns undefined instead of null when the highlighter constructor is unavailable
  2. The code only checks for null: if(U===null)return null;
  3. When U is undefined, it passes the null check but fails when trying to instantiate new U($,A)

How to Reproduce

The crash appears to occur when:

  1. Claude is rendering code output (e.g., file contents, patches, or code blocks)
  2. The syntax highlighter initialization fails or returns undefined
  3. Interestingly, the crash occurred while Claude was attempting to report this very bug, crashing during the rendering phase

Expected Behavior

The code should gracefully handle cases where the highlighter is unavailable by:

  • Checking for both null and undefined: if (!U || U === null) return null;
  • Or ensuring q4I() always returns null (not undefined) when unavailable
  • Or fixing the underlying initialization issue causing q4I() to return undefined

Suggested Fix

Change line 1137 from:

if(U===null)return null;

To:

if(!U)return null;

Or more explicitly:

if(U === null || U === undefined)return null;

Impact

This is a critical bug that causes complete crash of the CLI tool during normal operation, particularly when rendering code output or when the syntax highlighting library fails to load properly.

Additional Context

The stack trace shows the crash originates from:

  • useMemo hook in React rendering
  • Code highlighting component (f6 component based on context)
  • Likely during file write operations or patch display (HV9, DKH functions visible in stack)

Full crash log available upon request.

View original on GitHub ↗

5 Comments

github-actions[bot] · 8 months ago

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/14270
  2. https://github.com/anthropics/claude-code/issues/14329

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

pavanbilgi · 8 months ago

Also experiencing this issue.

Environment:

  • Claude Code version: 2.0.71
  • Platform: Linux 5.4.0-150-generic
  • Model: Opus 4.5

Error:
ERROR undefined is not a constructor (evaluating 'new G($,I,L)')

Stack trace points to the same syntax highlighting code path (useMemo in the bundled code).

jammin320 · 8 months ago

Additional root cause analysis: Chalk template parser

I've been experiencing the same crash on WSL Ubuntu (v2.0.72) and did some deep investigation that may complement your findings.

The trigger: The Chalk template literal parser crashes on standalone closing braces } in code content. Minimal reproduction:

const chalk = require('chalk');
chalk`}`;  // Throws: "Found extraneous } in Chalk template literal"

Why this matters: When Claude Code's Edit tool renders diffs, it appears to pass code through Chalk tagged templates (chalk...``) for syntax highlighting. Any code with closing braces (PHP, JavaScript, C, Java, JSON, CSS - basically everything) triggers the parser error.

Platform-specific behavior:
| Environment | Result |
|-------------|--------|
| WSL Ubuntu via Windows Terminal | ❌ Crashes |
| AlmaLinux (native Linux) | ✅ Works fine |

Same version (2.0.72), same files. The bug only manifests in certain terminal/platform combinations.

Connection to your analysis: Your finding that q4I() returns undefined instead of null is likely downstream of the Chalk parser failure. The chain appears to be:

  1. Chalk template parser encounters } → throws error
  2. Highlighter initialization catches error, returns undefined
  3. Null check passes (undefined !== null)
  4. new U($,A) with undefined constructor → crash

Operations affected: Only Edit tool diff rendering. Read, glob, and search operations work fine against the same files.

No workarounds found: Tested NO_COLOR=1, FORCE_COLOR=0, TERM=dumb, VS Code integrated terminal - all still crash on WSL.

This may also be related to #14180 (Unicode filename crashes) - same error signature, same platform bias toward Windows.

shawnm-anthropic · 8 months ago

This should be fixed in tomorrow's scheduled release (v2.0.74). Thanks for reporting!

github-actions[bot] · 8 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.