-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[style-engine] style-components resolutions does not work with npm
#28559
Comments
I have exactly the same problem, would really like to know how to solve this, |
This commands should get it working |
But isn't the point to NOT have to use those two dependencies?
|
I am using styled-components. Installing emotion defeats the entire purpose of using styled-components. |
Completely agree! |
ok, can you try clearing the cache |
Just did that. Still getting same error. Earlier I even deleted the node_modules folder. From my understanding, the styled-engine-sc package is not getting installed because the instructions on the Material UI Docs tell you to install the package "npm:@mui/styled-engine-sc@latest" which is for some reason not being recognized by npm. |
A work around might be to replace the dependency |
As the Docs say, "@mui/styled-engine" is a thin wrapper around emotion's styled() API. Using it instead of "@mui/styled-engine-sc" would mean using emotion. |
I'm also getting this error and is very weird seeing they said styled components would work the same as emotion. |
Thanks for providing the codesandbox but following the doc works fine in my local machine (I used with create-react-app). Can you provide the repo that we can reproduce? Note: you can check if the resolution works by looking at |
Have you done anything special that is not written in the doc? I think that my main problem (and might be @HyphenFrox's problem too) is that there is no "resolution" with npm (I am not using yarn). So, I presume that the docs assume that the developer is using yarn as their package manager? Or did you get it to work using npm as your package manager? If that is the case, then it would be very nice to get a npm solution, or to be specified in the doc that you HAVE to use yarn. I found out an example that gets it to work with npm (I think): example. Here, however, it is not as straightforward as just adding the two lines mentioned in doc to packet.json. Just correct me if I wrote something wrong. It could well be that npm does in fact have "resolve" nowadays. |
No. I did the same as the docs.
|
npm
Do you have any solution for those using npm as package manager? |
@AndreaEsposit the examples work with both npm and yarn. Have you tried:
Maybe we should add a note on the docs, that for npm it's best to use the examples |
Maybe we should follow - https://preactjs.com/guide/v8/switching-to-preact |
This works for new projects, yes, however it is not straightforward for ongoing projects. Seems like this example utilizes "react-app-rewired" and "customize-cra". Will try to mimic the example and I will update my comment if I get it to work. |
@siriwatknp , the code sandbox is the simplest way to reproduce the error I am getting. The resolutions field does not work with npm. |
@mnajdova I tried adding the exact same dependencies in my app as in the package.json of create-react-app-with-styled-components but my guess is that you are using |
I managed to get this working by adding in an alias to the resolve section in resolve:
{
alias: {
'@mui/styled-engine': '@mui/styled-engine-sc',
}
}, FWIW, I'm using ReactJS.Net so I can't use the CRA methods either. (or the emotion engine!) |
Both I would very much prefer a solution not requiring aliasing (or to be more specific, only rely on vanilla CRA), but if that's the only way forward, https://github.com/gsoft-inc/craco seems like a more up to date solution for CRA configuration handling. |
I am having the same issue, using
Fixed by running: My OS is Ubuntu. |
I will update the documentation with the following info:
We can probably get an inspiration from preact and see how they are solving the problem (from what I could see, they are depending on bundler's aliasing) |
We had the same issue. The solution was to add const withTM = require('next-transpile-modules')(['@mui/material', '@mui/system', '@mui/lab']); |
MUI looks for @emotion/react in styled-engine even after installing styled-engine-sc and setting up package aliases.
Current Behavior 😯
I get a compile time error
Module not found: can't resolve '@emotion/react' in 'C:\Users\Username\ProjectName\node_modules@mui\system\node_modules@mui\styled-engine'
Error from chokidar (C:): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.lo.tmp'
Expected Behavior 🤔
The app should be compiled using styled-engine-sc and styled components.
Steps to Reproduce 🕹
You can view the codesandbox
I installed MUI v5.0 by following the instructions at https://mui.com/getting-started/installation/#npm. i.e.
npm install @mui/material @mui/styled-engine-sc styled-components
Then edited the package.json by following instructions at https://mui.com/guides/styled-engine/
I added the dependency "@mui/styled-engine": "npm:@mui/styled-engine-sc@latest"
I added the resolutions field with:
"resolutions": {
"@mui/styled-engine": "npm:@mui/styled-engine-sc@latest"
},
Finally, I ran "npm install" to install all the dependencies.
But at compile-time, I got this error:
Module not found: can't resolve '@emotion/react' in 'C:\Users\Username\ProjectName\node_modules@mui\system\node_modules@mui\styled-engine'
Error from chokidar (C:): Error: EBUSY: resource busy or locked, lstat 'C:\DumpStack.lo.tmp'
I ran "npm outdated" and I got this result:
Package @mui/styled-engine
Current npm:@mui/styled-engine-sc@undefined
Wanted npm:@mui/styled-engine-sc@5.0.0
Latest npm:@mui/styled-engine-sc@5.0.0
So from my understanding styled-engine-sc did not get installed.
Your Environment 🌎
System:
OS: Windows 10 10.0.19043
Binaries:
Node: 14.17.6 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: Not Found
Edge: Spartan (44.19041.1023.0), Chromium (93.0.961.52)
npmPackages:
@mui/core: 5.0.0-alpha.48
@mui/material: ^5.0.1 => 5.0.1
@mui/private-theming: 5.0.1
@mui/styled-engine-sc: ^5.0.0 => 5.0.0
@mui/system: 5.0.1
@mui/types: 7.0.0
@mui/utils: 5.0.1
@types/react: 17.0.24
react: ^17.0.2 => 17.0.2
react-dom: ^17.0.2 => 17.0.2
styled-components: ^5.3.1 => 5.3.1
I used chrome version 93
The text was updated successfully, but these errors were encountered: