Skip to content

Bug: Cannot read properties of undefined (reading '__CLIENT_INTERNALS_…') on Vite + React 19 #180

@dbuezas

Description

@dbuezas

Environment

  • agentation@3.0.2
  • React 19.x, ReactDOM 19.x
  • Vite (dev server, ESM)

Repro

  1. Install agentation in a Vite + React 19 app
  2. Render <Agentation endpoint="…" />
  3. Click any element with the toolbar active

Error

Uncaught TypeError: Cannot read properties of undefined
  (reading '__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE')
  at getReactDispatcher (agentation.js:12205)
  at probeComponentSource (agentation.js:12273)
  at probeSourceWalk (agentation.js:12308)
  at getSourceLocation (agentation.js:12336)
  at detectSourceFile (agentation.js:13270)
  at HTMLDocument.handleClick (agentation.js:14458)

Root cause

src/utils/source-location.ts uses a default import:

import React from "react";

react does not have a default export — it's a namespace. Under tsup's CJS interop in your dev environment (and React 18's looser shape) the default-import shim makes this work. But under Vite's ESM resolution with React 19's exports map, the default import resolves to undefined, so React.__CLIENT_INTERNALS_… throws inside getReactDispatcher.

This is visible in the published bundle at dist/index.mjs line 7050:

// src/utils/source-location.ts
import React from "react";

Fix

Change the source to a namespace import:

import * as React from "react";

That keeps the React 18 / React 19 dual-shape guard inside getReactDispatcher working as intended (since the function already handles both __CLIENT_INTERNALS_… and __SECRET_INTERNALS_…).

Workaround for users on the current release

Apply a pnpm patch (or equivalent) editing dist/index.mjs line 7050 from import React from "react" to import * as React from "react".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions