-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Description
React version: 19.0.0
Steps To Reproduce
- Clone this repo: https://github.com/yesquesasi/webpack-5-react-boilerplate
- Checkout to branch
react-profiler-test - Install dependencies:
yarn install - Create a production build:
yarn build - Run the application:
yarn prod - Open page in browser: http://localhost:8005/
- Open browser console, an error appears:
Uncaught TypeError: Cannot read properties of undefined (reading 'd')
I've forked the repo webpack-5-react-boilerplate, which is a perfectly working React 19 + Webpack repository, adding the code the React.Profiler documentation points out to to enable React.Profiler in production, you can see that code in this PR - with this you can reproduce the error that I'm seeing in another larger application.
The current behavior
I have a larger application using React.Profiler in production, I followed the steps to enable it and everything was working as expected, I was using [email protected] and [email protected]
After upgrading to [email protected] (and even 19.1.0) I started seeing that React.Profiler no longer worked in the production build (it does work in development tho) having a very similar runtime error to the one above when I opened any page: Uncaught TypeError: Cannot read properties of undefined (reading 'd'), since it's the production build everything is minified and I haven't had luck finding more details about the error.
Research made
I compared the code inside node_modules for [email protected] and [email protected] to see if I was able to find any ways to fix it, but had no luck. The main difference between those 2 versions are:
The exported configuration in package.json
We have this for [email protected] in package.json
....
"exports": {
".": "./index.js",
"./profiling": "./profiling.js",
....
whereas in [email protected] in package.json the exports values are quite different using default:
...
"exports": {
".": {
"react-server": "./react-dom.react-server.js",
"default": "./index.js"
},
"./profiling": {
"react-server": "./profiling.react-server.js",
"default": "./profiling.js"
},
....
I thought this meant I needed to change the way I create the alias in my webpack config, but I tried several different ways and nothing worked while building
'react-dom$': 'react-dom/profiling' // original code from documentation (causing bug)
'react-dom$': 'react-dom/profiling/default' // fails to build
'react-dom$': 'react-dom/profiling.default' // fails to build
'react-dom$': 'react-dom/profiling/profiling.js' // fails to build
Contents of profiling.js
Looking again at the differences in versions in node_modules I found that the file that ends up being export by react-dom/profiler.js changed from versions, the one in [email protected] was minified whereas the one in [email protected] is not precisely minified.
I had no further findings in this area but I've updated the node modules to a repo for easier comparision:
[email protected] - profiling.js
[email protected] - cjs/react-dom-profiling.profiling.js
VS
[email protected] - profiling.js
[email protected] - cjs/react-dom.profiling.min.js
The expected behavior
I'd appreciate your help to find out why this is not working and how to fix it.