-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Migrating to Pigment CSS with react/webpack #43597
Comments
Yes you can, you can use the Here is an example
We have one example in the Pigment CSS repo, but we should likely add one for Material UI as well. Let me know if the example above is enough for your use-case. |
Thanks for the response! This did not seem to be enough for our use case, however. Here is our full webpack.config:
And the error I am seeing when I try to run the project: [BABEL] Note: The code generator has deoptimised the styling of [path-to-node-modules]/@mui/icons-material/esm/index.js as it exceeds the max of 500KB. |
I switched from named to default imports for all my mui icons and it resolved this error: [BABEL] Note: The code generator has deoptimised the styling of [path-to-node-modules]/@mui/icons-material/esm/index.js as it exceeds the max of 500KB. |
@clairefields15 Could you share a repo for me to take a look at ? |
@brijeshb42 this was a bit challenging, because the repo is an enterprise project so I can't share all of it. I was able to spin up a small project with a very similar structure and when I added the I will continue to add components to the repo to attempt to replicate the same error as I see in my other project.
In the test repo I see
|
I updated this test repo and the error with the StyledEngineProvider occurred the first time I tried to run the app with the modal component included. Commenting the modal component in and out can sometimes reproduces the error, but it is inconsistent. What is consistent is an error "cannot read properties of undefined (reading 'modal')" which is mystifying because I don't personally see anything wrong in the code. When I console.log |
I'm also struggling with migration a webpack + typescript project to pigment-css. It would be nice if a webpack guide could be included in https://mui.com/material-ui/migration/migrating-to-pigment-css/ |
Hey all, an update on this. While I was able to fix the config to work with Webpack, I found an issue that is in the core right now that relates to how we do sx prop transform and it's relation to mangling. This affects all the bundlers and not just webpack but is more prominent for Webpack. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note @clairefields15 How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Reopening as the PR only fixes the issue partially. I'll add a proper fix for your specific code. |
@clairefields15 Can you try with the latest version of Pigment CSS packages One extra change I'd add to your source is add import '@mui/material-pigment-css/styles.css' in You might have to add a version override for I was able to test dev server and built files with these changes locally. |
@brijeshb42 thank you for looking at this! We will give it a try in the real repo and let you know how it goes. |
@brijeshb42 thanks again for looking into this. I've been looking into this issue with @clairefields15. Unfortunately, After following the steps you outlined above, we're still encountering the same error message as follows. We're on Windows OS by the way and using node v20.15.1.
I also saw the error reported as follows while debugging, which seems a little more helpful:
If I set a breakpoint at line 57, I hit the breakpoint a bunch of times and
But before I hit this error, when execution stops at this breakpoint, things look correct: The error above always reports that this error is emanating from a component in my source that imports
Just to confirm, we included this in our source:
We added a version override for
We double checked and confirmed that version Otherwise we followed the Pigment CSS migration guide closely. I was wondering a couple things though as I went through the guide. Looking at the error it doesn't seem like it's necessarily related to any of these things, but I just wanted to check some assumptions while as I was posting this anyway in case something stands out:
and
I'll try and debug it some more to see if anything else stands out. Thanks again for the help. I can also work again on trying to reproduce the bug in a repo that I can share. |
@pszujewski Is it the same code that you've posted in the repo ? If not, can you update the repo with the latest code.
const defaultSx: SxProps = { color: "#fff", /* etc... */ };
function Example({ sx }: { sx?: SxProps }) {
return (
<Box sx={sx ?? defaultSx} />
);
} Here, sx={{
...defaultSx,
color: 'red',
backgroundColor: props.red
}} will work. Same is valid for your other example.
|
Thanks, @brijeshb42. No the screenshots and error summaries were from trying to integrate pigment/mui v6 into a private repo. Nevertheless, we were able to reproduce the same error in the public test repo @clairefields15 created here: https://github.com/clairefields15/webpacktest. Have you tried this repo out? The error is the same as above: EvalError: Cannot read properties of undefined (reading 'StyledEngineProvider') However, we weren't able to reproduce the error every time we ran webpack + pigment in this test project. Only a few times. In our private repo it occurs every time. So I will work on trying to get the error to more reliably occur in the public test repo, and I will also update the public test repo to use this newer version of I'll post here again next week as I look into this further starting from this public test repo: https://github.com/clairefields15/webpacktest Thank you! |
Related page
https://mui.com/material-ui/migration/migrating-to-pigment-css/
Kind of issue
Unclear explanations
Issue description
Is it possible to migrate to pigment css in a project that uses react/webpack? For various reasons, our project cannot use nextjs or vite but we would like to take advantage of the performance improvements of pigment.
Context
No response
Search keywords: pigment, react, webpack
The text was updated successfully, but these errors were encountered: