material-ui: Error: "export 'useId' (imported as 'React') was not found in 'react'" after upgrading to v5.2.0
Current behavior šÆ
Building a project on React 17 throws the following errors when running build.

@mui/material: v5.2.0 webpack: 5.64.2 react: 17.0.2
EDIT: Seems to be related to a change in @mui/utils where an attempt is made to check for the existence of useId in react: https://github.com/mui-org/material-ui/commit/3323b23d8c5b6c03627f9c46634db3b595795433#diff-41d8fb02706e8d95b775dfa0caadade00dbbcb017d7f2c7acbc3100c5a02d46f
Expected behavior š¤
Build should work on React 17 as v5.2.0 is a minor release and React 18, which includes these imports, is not yet released.
Steps to reproduce š¹
Steps:
- Clone the following repo: https://github.com/sachinahya/mui-5.2.0-build-error
- Run
yarn build.
To reproduce working example:
- Change version of
@mui/materialin package.json to~5.1.0. - Add the following resolutions to package.json:
"resolutions": {
"@mui/utils": "~5.1.0"
},
Context š¦
No response
Your environment š
`npx @mui/envinfo`
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 38
- Comments: 34 (9 by maintainers)
Commits related to this issue
- mui 5.2.0 bug workaround https://github.com/mui-org/material-ui/issues/29860 — committed to bit-demos/ui-library-wrappers by benjgil 3 years ago
- resolved issue with material ui see https://github.com/mui-org/material-ui/issues/29860 upstream issue is https://github.com/webpack/webpack/issues/14814 — committed to quipcode/halla by quipcode 3 years ago
- Fixed MUI version to 5.1.1 see https://github.com/mui/material-ui/issues/29860#issuecomment-977167464 — committed to dotGems/gems-ui-library by DominicF96 2 years ago
Should be fixed in 5.2.1. Make sure you have
@mui/material@^5.2.1and@mui/utils@^5.2.1in your dependency tree.@eps1lon For me itās just a warning. But thereās more than the one mentioned here:
So, this is pretty hacky, but you should be able to resolve this temporarily/quickly while weāre still waiting for this by:
@mui/material(and all its dependencies - I had to add all of the below in mypackage.jsonāsdependencies:package.json:I would appreciate it, if people would upvote the upstream issue instead. Without a resolution from Webpack you will always get these warnings once React 18 is released and youāre still using React 17. I donāt think this is a reasonable expectation for libraries imposed by bundlers.
Weāll revert the responsible changes in the meantime. But once React 18 is released, youāll encounter this issue again.
Me too, and also this import:
Iām using with nextjs 12.0.4
I am facing this issue Attempted import error: āuseSyncExternalStoreā is not exported from āreactā (imported as āReact2ā) in react 16.13. But not able to figureout from where it is getting.
A way to bypass the warning is to start webpack with
--no-client-overlay-warnings, until a fix is released. The warning is still there in console, but at least you donāt have to click the close icon up in right every time it reloads.strictExportPresence: falseonly makes it a āwarningā. The problem persists. And the overlay generated in webpack with the warnings seems to be causing other issues with code updates.I still got an error ⦠trying with disable esmodules in babel
@solarmosaic-colin-young That works for me! I noticed it would be solved we pinned the version down to
5.1.1but I was struggling with how to solve it.^5.x.xforced me to install the latest one5.2.0which caused the warnings. Thank you!Had the same error for my own npm component library created using mui v5. changing mui, emotion versions didnāt help.
this was the rollup.config.ts before:
following changes in rollup.config.ts solved it:
Fix
New rollup.config.ts that uses only cjs check rollup output formats here
Sample repositories: component library consumer of the library
Also experiencing this on a new application. Same versions as previous app however (but prev app works fine, weird).
Versions
Warnings areā¦
And they generate a full screen overlay with webpack, which iāve had to disable.
strictExportPresence: falsein webpack config.module doesnt seem to do much for me.