diff --git a/admin/test-bad-package/README.mdx b/admin/test-bad-package/README.mdx index 40abc5448c2b..260522db2417 100644 --- a/admin/test-bad-package/README.mdx +++ b/admin/test-bad-package/README.mdx @@ -12,7 +12,7 @@ import {version as ReactVersion} from 'react'; import {version as ReactDOMVersion} from 'react-dom'; export function TestComponent() { - const expectedVersion = 18; + const expectedVersion = 19; if (!ReactVersion.startsWith(`${expectedVersion}`)) { throw new Error( `'test-bad-package/README.mdx' is rendered with bad React version: ${ReactVersion}`, diff --git a/packages/docusaurus/src/webpack/base.ts b/packages/docusaurus/src/webpack/base.ts index 3ffda658fedd..4dce834d9075 100644 --- a/packages/docusaurus/src/webpack/base.ts +++ b/packages/docusaurus/src/webpack/base.ts @@ -35,14 +35,19 @@ const LibrariesToTranspileRegex = new RegExp( LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'), ); -const ReactAliases: Record = process.env - .DOCUSAURUS_NO_REACT_ALIASES - ? {} - : { - react: path.dirname(require.resolve('react/package.json')), - 'react-dom': path.dirname(require.resolve('react-dom/package.json')), - '@mdx-js/react': path.dirname(require.resolve('@mdx-js/react')), - }; +function getReactAliases(siteDir: string): Record { + // Escape hatch + if (process.env.DOCUSAURUS_NO_REACT_ALIASES) { + return {}; + } + const resolveSitePkg = (id: string) => + require.resolve(id, {paths: [siteDir]}); + return { + react: path.dirname(resolveSitePkg('react/package.json')), + 'react-dom': path.dirname(resolveSitePkg('react-dom/package.json')), + '@mdx-js/react': path.dirname(resolveSitePkg('@mdx-js/react')), + }; +} export function excludeJS(modulePath: string): boolean { // Always transpile client dir @@ -186,7 +191,7 @@ export async function createBaseConfig({ process.cwd(), ], alias: { - ...ReactAliases, + ...getReactAliases(siteDir), '@site': siteDir, '@generated': generatedFilesDir, ...(await loadDocusaurusAliases()), diff --git a/website/package.json b/website/package.json index fc61ef63ae06..4f1442b77001 100644 --- a/website/package.json +++ b/website/package.json @@ -58,8 +58,8 @@ "netlify-plugin-cache": "^1.0.3", "pure-react-carousel": "^1.30.1", "raw-loader": "^4.0.2", - "react": "^18.0.0", - "react-dom": "^18.0.0", + "react": "^19.0.0", + "react-dom": "^19.0.0", "react-lite-youtube-embed": "^2.3.52", "react-medium-image-zoom": "^5.1.6", "recma-mdx-displayname": "^0.4.1",