@@ -2,7 +2,7 @@ import type { NextConfig } from 'next';
2
2
import type { Configuration as WebpackConfig } from 'webpack' ;
3
3
import { DefinePlugin } from 'webpack' ;
4
4
5
- import { addScopedAlias , resolveNextConfig } from '../utils' ;
5
+ import { addScopedAlias , resolveNextConfig , setAlias } from '../utils' ;
6
6
7
7
const tryResolve = ( path : string ) => {
8
8
try {
@@ -20,33 +20,32 @@ export const configureConfig = async ({
20
20
nextConfigPath ?: string ;
21
21
} ) : Promise < NextConfig > => {
22
22
const nextConfig = await resolveNextConfig ( { nextConfigPath } ) ;
23
- baseConfig . resolve ??= { } ;
24
- baseConfig . resolve . alias ??= { } ;
25
- const aliasConfig = baseConfig . resolve . alias ;
26
23
27
24
addScopedAlias ( baseConfig , 'next/config' ) ;
25
+
26
+ // @ts -expect-error We know that alias is an object
27
+ if ( baseConfig . resolve ?. alias ?. [ 'react-dom' ] ) {
28
+ // Removing the alias to react-dom to avoid conflicts with the alias we are setting
29
+ // because the react-dom alias is an exact match and we need to alias separate parts of react-dom
30
+ // in different places
31
+ // @ts -expect-error We know that alias is an object
32
+ delete baseConfig . resolve . alias ?. [ 'react-dom' ] ;
33
+ }
34
+
28
35
if ( tryResolve ( 'next/dist/compiled/react' ) ) {
29
36
addScopedAlias ( baseConfig , 'react' , 'next/dist/compiled/react' ) ;
30
37
}
31
38
if ( tryResolve ( 'next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js' ) ) {
32
- addScopedAlias (
39
+ setAlias (
33
40
baseConfig ,
34
41
'react-dom/test-utils' ,
35
42
'next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js'
36
43
) ;
37
- } else {
38
- const name = 'react-dom/test-utils' ;
39
- if ( Array . isArray ( aliasConfig ) ) {
40
- aliasConfig . push ( {
41
- name,
42
- alias : name ,
43
- } ) ;
44
- } else {
45
- aliasConfig [ name ] = name ;
46
- }
47
44
}
48
45
if ( tryResolve ( 'next/dist/compiled/react-dom' ) ) {
49
- addScopedAlias ( baseConfig , 'react-dom' , 'next/dist/compiled/react-dom' ) ;
46
+ setAlias ( baseConfig , 'react-dom$' , 'next/dist/compiled/react-dom' ) ;
47
+ setAlias ( baseConfig , 'react-dom/client' , 'next/dist/compiled/react-dom/client' ) ;
48
+ setAlias ( baseConfig , 'react-dom/server' , 'next/dist/compiled/react-dom/server' ) ;
50
49
}
51
50
52
51
setupRuntimeConfig ( baseConfig , nextConfig ) ;
0 commit comments