Skip to content

Commit bdeb187

Browse files
committed
fix(examples): deduplicate React in Next.js monorepo example
Add webpack alias to resolve react/react-dom from the app's own node_modules, preventing the "invalid hook call" error caused by two different React copies in the pnpm workspace.
1 parent 5a12040 commit bdeb187

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

examples/next/next.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
import path from 'node:path';
2+
import { fileURLToPath } from 'node:url';
3+
4+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
5+
16
/** @type {import('next').NextConfig} */
27
const nextConfig = {
38
reactStrictMode: true,
9+
webpack: (config) => {
10+
// Deduplicate React in the monorepo so linked workspace packages
11+
// resolve the same copy as the app (prevents "invalid hook call").
12+
config.resolve.alias = {
13+
...config.resolve.alias,
14+
react: path.resolve(__dirname, 'node_modules/react'),
15+
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
16+
};
17+
18+
return config;
19+
},
420
};
521

622
export default nextConfig;

0 commit comments

Comments
 (0)