Material UI build fails because Emotion is missing behind the styled engine
Your error
Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine'1 more line it can showFix it fast
Most common cause, 1 of 2Emotion was never installed
Install both Emotion packages beside Material UI, the same way the official install command does, and commit the updated lockfile.
npm install @mui/material @emotion/react @emotion/styledShort answer
Module not found: Can't resolve '@emotion/react' in node_modules/@mui/styled-engine means Material UI's default styling engine imports Emotion and Emotion is not installed. @mui/material marks it as an optional peer, which npm never installs on its own. Run npm install @emotion/react @emotion/styled, or alias @mui/styled-engine to @mui/styled-engine-sc when you use styled-components. Applies to MUI 9.5.
Which cause do you have?
List the styling packages in the tree. Empty entries for both Emotion packages and no styled-components point to cause 1. styled-components or @mui/styled-engine-sc in the list point to cause 2.
npm ls @emotion/react @emotion/styled @mui/styled-engine @mui/styled-engine-sc styled-componentsThen find the line you see in this list and open its fix:
- 1Emotion was never installed
npm ls prints (empty) for @emotion/react and @emotion/styled, and the project has no styled-components either - 2The app uses styled-components, but the engine was never swapped
package.json lists styled-components and @mui/styled-engine-sc, yet the error still names @emotion/react inside @mui/styled-engine
What does the error look like?
Module not found: Can't resolve '@emotion/react' in 'E:\frontend\node_modules\@mui\styled-engine'Module not found: Can't resolve '@emotion/styled' in '/app/node_modules/@mui/styled-engine'
Cause 1 of 2
Emotion was never installed
You seenpm ls prints (empty) for @emotion/react and @emotion/styled, and the project has no styled-components either
Check
Can't resolve '@emotion/react' in @mui/styled-engine appears when Material UI went in on its own. Emotion is its default styling engine, and @mui/material lists @emotion/react and @emotion/styled as peer dependencies flagged optional in peerDependenciesMeta. npm has installed ordinary peers by default since v7, but its docs say it never installs optional ones, so npm install @mui/material alone leaves Emotion out.
npm view @mui/material peerDependenciesMeta
npm ls @emotion/react @emotion/styledFix
Install both Emotion packages beside Material UI, the same way the official install command does, and commit the updated lockfile.
npm install @mui/material @emotion/react @emotion/styledVerify
npm ls now shows both packages, and the dev server or production build compiles.
npm ls @emotion/react @emotion/styled
npm run buildConfirmed by mui.com
Cause 2 of 2
The app uses styled-components, but the engine was never swapped
You seepackage.json lists styled-components and @mui/styled-engine-sc, yet the error still names @emotion/react inside @mui/styled-engine
Check
Out of the box @mui/material depends on @mui/styled-engine, which is the Emotion adapter. Adding @mui/styled-engine-sc to the project changes nothing until the bundler loads it wherever @mui/styled-engine is imported, so the Emotion adapter keeps running and keeps asking for @emotion/react.
grep -rn "styled-engine" webpack.config.js tsconfig.json package.jsonFix
With npm, which has no resolutions field, add a bundler alias and a matching TypeScript paths entry, as the MUI guide shows. With Yarn, point @mui/styled-engine at the sc package in both dependencies and resolutions.
// webpack.config.js (npm)
module.exports = {
resolve: {
alias: {
'@mui/styled-engine': '@mui/styled-engine-sc',
},
},
};
// tsconfig.json (npm)
{
"compilerOptions": {
"paths": {
"@mui/styled-engine": ["./node_modules/@mui/styled-engine-sc"]
}
}
}
// package.json (Yarn)
"dependencies": { "@mui/styled-engine": "npm:@mui/styled-engine-sc@latest" },
"resolutions": { "@mui/styled-engine": "npm:@mui/styled-engine-sc@latest" }Verify
Rebuild; the output no longer mentions Emotion. grep -c should print 0.
npm run build 2>&1 | grep -c "@emotion"Confirmed by mui.com
How do I stop it coming back?
- List both Emotion packages as direct dependencies even if no file of yours imports them, because Material UI's default engine loads them.
- Choose one styling engine per app, and add the alias in the same commit that adds @mui/styled-engine-sc.
- Use the full install line from the MUI docs in setup scripts and new workspace templates, so a fresh package gets all three packages.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.