@@ -10,17 +10,16 @@ const supportsReactCreateRoot = parseInt(ReactDOM.version.split('.')[0], 10) >=
10
10
// eslint-disable-next-line @typescript-eslint/no-explicit-any
11
11
let reactDomClient : any ;
12
12
if ( supportsReactCreateRoot ) {
13
- // eslint-disable-next-line camelcase
14
- if ( __webpack_require__ ) {
15
- // we are in a Webpack environment (and in a node-modules directory of another project)
16
- // See https://webpack.js.org/guides/dependency-management/#context-module-api
17
- const reactDomContext = require . context ( 'react-dom/' , false , / ^ c l i e n t \. j s $ / ) ;
18
- reactDomClient = reactDomContext ( 'react-dom/client.js' ) ;
19
- } else {
20
- // we want a dynamic require here so that webpack doesn't rewrite it
21
- const reactDomClientName = 'react-dom/client' ;
22
- // eslint-disable-next-line global-require,import/no-dynamic-require
23
- reactDomClient = require ( reactDomClientName ) ;
13
+ // This will never throw an exception, but it's the way to tell Webpack the dependency is optional
14
+ // https://github.com/webpack/webpack/issues/339#issuecomment-47739112
15
+ // Unfortunately, it only converts the error to a warning.
16
+ try {
17
+ // eslint-disable-next-line global-require,import/no-unresolved
18
+ reactDomClient = require ( 'react-dom/client' ) ;
19
+ } catch ( e ) {
20
+ // We should never get here, but if we do, we'll just use the default ReactDOM
21
+ // and live with the warning.
22
+ reactDomClient = ReactDOM ;
24
23
}
25
24
}
26
25
0 commit comments