Skip to content

App Router crash: reactfire 4.2.4/4.2.5 throw "dynamic usage of require is not supported" on the client #759

Description

@tyler-reitz

Summary

Reactfire 4.2.4 and 4.2.5 (current latest) crash on the client in Next.js App Router apps that render a data hook (e.g. useFirestoreDocData). use-sync-external-store/shim (a CJS module) is bundled into our ESM dist, which makes the bundler emit a dynamic require(). In a strict-ESM browser context it throws at module evaluation of the reactfire chunk:

Error: dynamic usage of require is not supported

Any App Router page that loads a reactfire data-hook chunk breaks on the client. Server prerender is unaffected (Node has require).

Affected versions

  • 4.2.4, 4.2.5: affected (ship the bundled shim with the dynamic require).
  • 4.2.3: clean (predates the current build toolchain; ESM dist imports react directly, no require).

Reproduction

  1. Next.js App Router app on reactfire 4.2.5.
  2. Render a client component using a data hook, e.g. useFirestoreDocData.
  3. Load the page: the browser console throws Error: dynamic usage of require is not supported at module evaluation.

Root cause

The build-tooling migration (around 4.2.4) began bundling the CJS use-sync-external-store/shim into the ESM output, producing a runtime require() that does not exist in strict ESM.

Fix

Externalize use-sync-external-store/shim so the consumer's bundler resolves it (it is already a runtime dependency). Non-breaking; the shim's React 16/17 fallback is preserved. Fix PR incoming.

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