material-ui: create-react-app-with-styled-components fails with Can't resolve '@emotion/react'
The styled-components example fails with not finding emotion
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
Module not found: Can't resolve '@emotion/react' in '/path/to/create-react-app-with-styled-components/node_modules/@material-ui/system/node_modules/@material-ui/styled-engine'
Expected Behavior 🤔
Steps to Reproduce 🕹
Follow the example:
curl https://codeload.github.com/mui-org/material-ui/tar.gz/next | tar -xz --strip=2 material-ui-next/examples/create-react-app-with-styled-components
cd create-react-app-with-styled-components
npm install
npm start
Context 🔦
Your Environment 🌎
`15:50 $ npx @material-ui/envinfo
npx: installed 2 in 4.683s
System:
OS: macOS 11.4
Binaries:
Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
Yarn: Not Found
npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
Browsers:
Chrome: Not Found
Edge: 92.0.902.62
Firefox: 90.0.2
Safari: 14.1.1
npmPackages:
@material-ui/core: next => 5.0.0-beta.4
@material-ui/lab: next => 5.0.0-alpha.43
@material-ui/private-theming: 5.0.0-beta.4
@material-ui/system: 5.0.0-beta.4
@material-ui/types: 6.0.2
@material-ui/unstyled: 5.0.0-alpha.43
@material-ui/utils: 5.0.0-beta.4
@types/react: 17.0.19
react: latest => 17.0.2
react-dom: latest => 17.0.2
styled-components: latest => 5.3.0`
Don't forget to mention which browser you used.
Output from `npx @material-ui/envinfo` goes here.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 9
- Comments: 41 (11 by maintainers)
Commits related to this issue
- additional dependency due to bug https://github.com/mui-org/material-ui/issues/27846 — committed to DoshiNeil/n8-fpl-eta-fe by nzymtech 3 years ago
It works after installing
@emotion/styledAND@emotion/reactwhich defeats the purpose of having the style engines disconnected and pluggable (as per the documenation)for those getting error try this npm install @mui/material @emotion/react @emotion/styled
I am getting this warning in Vercel:
Could this be related? I am seeing
Module not found: Can't resolve '@mui/styled-engine'after following all steps outlined in docs, but only when deploying to Vercel. Works fine locally.I’m facing this issue also with yarn… After initially installing with npm, I deleted my
node_modulesandpackage-lock.jsonand installed everything with yarn. Still got that can’t resolve module error. Installed@emotion/reactand@emotion/styledand now it’s working. But as mentioned, having bothstyled-components(which I want to use) andemotionjust defeats the purpose…Any updates on this will be greatly appreciated 🙏
Still encountering this issue as of today (npm
8.19.3).I was able to get past the issue by following the
@mui/styled-engineguide, and installing@emotion/reactand@emotion/styled.The MUI Installation docs might need to be updated to reflect that this is necessary. The current docs imply that you need to do EITHER:
OR
…when the actual solution is:
This still happens, even after installing the package
I ran into this behavior with the 5.0 release, trying to use CRA, npm, and styled-components. Installing
@emotion/styledand@emotion/reactdoes fix it, as per https://github.com/mui-org/material-ui/issues/27846#issuecomment-902448679.What’s the current state of this? It sounds like the options are either:
In case this helps anyone else - I had this issue with yarn workspaces. The issue was twofold:
resolutionssection must go in the workspace’s rootpackage.json.@mui/styled-engineto@mui/styled-engine-scin theresolutions, you cannot also alias it through craco or tsconfig paths.If you inspect
<project root>/node_modules/@mui/styled-engine/package.jsonyou will notice it is@mui/styled-engine-sc; this is how you know the resolution is working.Same here but with Gatsby. Ofc I tried style guide, adding custom webpack configuration ,
resolutionsinpackage.jsonand nothing helps.Problem happens with yarn
I got the same issue as @OPerel, I’m using yarn, I’d like to use
styled-components, but now it’s only working when I installed@emotion/reactand@emotion/styledwithstyled-components, this is not ideal. I followed this document: https://mui.com/guides/styled-engine/Same here, but when i build a docker image
And
I am migrating v4 to v5 and got same error with styled components. It didn’t work for me by following the change in https://mui.com/guides/styled-engine/.
After checked the repo in https://github.com/mui-org/material-ui/tree/next/examples/create-react-app-with-styled-components, I tried to add the following alias into my webpack config file and it works:
Thanks for the report. I can reproduce that it does not work with npm.
I tried and it works with yarn. I believe it’s related to the package alias we use, namely because of the changes done in https://github.com/mui-org/material-ui/pull/27591.
Based on https://github.com/mui-org/material-ui/pull/27088#issuecomment-885278495 I remember that @oliviertassinari tested that it works with npm. Olivier can you verify that it works and maybe share which version of npm you are using?
I understand what’s your issue. And I already started working on this.