From a0cdd02829b2e6f2aa69e90afc29a8820a2b1f56 Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 7 Jan 2025 00:31:59 +0800 Subject: [PATCH] Try fix --- packages/integrations/react/src/version.ts | 10 ++++++++-- pnpm-lock.yaml | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/integrations/react/src/version.ts b/packages/integrations/react/src/version.ts index dc3a7a85ae..28fb49c725 100644 --- a/packages/integrations/react/src/version.ts +++ b/packages/integrations/react/src/version.ts @@ -1,10 +1,16 @@ -import { version as ReactVersion } from 'react-dom'; +import { createRequire } from 'node:module'; export type SupportedReactVersion = keyof typeof versionsConfig; export type ReactVersionConfig = (typeof versionsConfig)[SupportedReactVersion]; export function getReactMajorVersion(): number { - const matches = /\d+\./.exec(ReactVersion); + // NOTE: Do not import `version` from `react-dom` because in 2025 React 19 still relies on + // `process.env.NODE_ENV` to determine export dev or prod code, and if we import `react-dom` + // too early (e.g. in the astro config) before we set `process.env.NODE_ENV`, it may reference + // the dev code, and then `react` will reference the prod code, and we get a mismatch of + // `TypeError: dispatcher.getOwner is not a function` + const pkgJson = createRequire(import.meta.url)('react-dom/package.json'); + const matches = /\d+\./.exec(pkgJson.version); if (!matches) { return NaN; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dc70723f92..cad6a8242f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9003,7 +9003,6 @@ packages: libsql@0.4.5: resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==} - cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] lilconfig@3.1.3: