From 39dc438426b837abe7eb45cd29f7cef11bcf1383 Mon Sep 17 00:00:00 2001 From: Tyler Dixon Date: Fri, 24 Jul 2026 12:46:20 -0700 Subject: [PATCH] fix: externalize useSyncExternalStore shim to fix App Router crash Bundling use-sync-external-store/shim (a CJS module) into the ESM dist makes rolldown emit a dynamic require() that throws "dynamic usage of require is not supported" when a reactfire data hook loads client-side in a Next.js App Router (strict ESM) context. This regression shipped in 4.2.4 and 4.2.5; 4.2.3 predates the current build toolchain and is clean. Externalizing the shim lets the consumer's bundler resolve it (it is already a runtime dependency), removing the require from our dist while keeping the shim's React 16/17 fallback. Verified the throw path is absent from the built ESM dist and from a rebuilt Next.js App Router client chunk. --- vite.config.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vite.config.ts b/vite.config.ts index 85660256..30d83cb9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,6 +12,12 @@ console.log(`ReactFire v${version}`); const externals = [ 'react', + // Externalize the useSyncExternalStore shim so the consumer's bundler resolves it. + // Bundling this CJS module into the ESM output makes rolldown emit a dynamic require() + // that throws ("dynamic usage of require is not supported") when a reactfire data hook + // loads client-side in a Next.js App Router (strict ESM) context. Externalizing keeps + // the shim's React 16/17 fallback intact while removing the require from our dist. + 'use-sync-external-store/shim', 'firebase', 'firebase/app', 'firebase/firestore',