-
-
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
Uncaught TypeError: styled_default is not a function #36511
Comments
We need more information in order to understand your issue. Can you provide some kind of reproduction? Also, please tell us what you updated in |
@hbjORbj that's exactly the problem. I can't reproduce an example, because I don't know what is wrong. Because all I see is this in my console: What can I provide with this single line? However, this is my update in the As you can see the only major change is In fact, when this error does not happen, I can use all of the date-time components and they work just fine. My problem is that I have no clue why this happens. And why it happens only sometimes. I have no idea how to debug it. |
@hbjORbj this is a reproducible repo, though it's not minimal. Please clone, I'm also going to create a bug issue for this. Thank you. |
It's not clear from the description of the issue, but it is likely related to some version of vite (or the caching algorithm used). I would propose trying #32727 (comment), #32727 (comment) or any other suggestion from that issue. I am not sure how we can help on MUI's side. |
@mnajdova thank you for answering. I have provided a reproducible example. I think it's related to MUI, because it happens in the By the way, I tried everything in that issue. And nothing worked. Removing |
I guess then we can consider this duplicate of #31835 |
@mnajdova Yes, I think it's similar. But please don't close this as that is not answered after almost a year. Please take this error more seriously. If necessary, could you talk to Vite team? Your voice would have a higher impact. |
Same issue here, I didn't update my modules or anything. Just used styled() and . The Code worked at first, but suddenly I got an "createTheme_default is not a function at Box.js" Error. After reverting everything back to the latest known working codebase I get the "styled_default is not a function at Popper.js" Error. |
Update on mine, I'm still not 100% sure what caused it, but after multiple days of troubleshooting, it has started to work again, so here are some things I tried along the way.
"@mui/icons-material": "^5.10.3",
"@mui/material": "^5.10.3",
Hope this helps :) |
The Vite team found the bug. It's in the bundling. |
But they don't clarify the solution, I've been reading about the issue for 3 hours and there's no solution, Vite is totally buggy |
@martingalenda try to reorder your imports. That helped me. |
@TurtleSocks +1 |
It gave the same error for Grid2, At start everything was working fine for Grid v2, even hosted my application, tested many times , until after some time I tried to clean up the code and did some edits with the imports , wrote many of them together like |
/ |
change import statement to import ThemeProvider from "@mui/material/styles/ThemeProvider"; |
Note: It may not be helpful but it was my observation and little debugging |
I had the same problem, after I used Unstable_Grid2 |
Had the issue few hours ago when I started using For what it's worth here the changes:
It didn't seem necessary but I also change the imports into: import { Unstable_Grid2 as Grid } from "@mui/material"; |
I am experiencing the issue, I added an accordion, the error started, then removed all the code and the error persisted, making me think it's something in the Vite build that gets left over or something like that. I tried reordering the imports, nothing worked in that regard. I just finished deleting and reintalling my node_modules and this also didn't work. Still have not found a workable solution. This project was running perfectly on Creat-React-App, so only thing I can think to point at is Vite? ------- Edit after a few hours: I had the issue with Grid2, so I reverted everything back to the first version of Grid, and that made it load again. Will see if it holds stable. Seems the problem stems from Popper and Grid, and has something to do with the way they are imported 🤔 |
Problem descriptionI've been experiencing the The problem lies in the way Yarn is installing MUI and Emotion packages. For the Next.js application it's installing MUI and Emotion in the workspace's own node_modules folder. But for the shared components workspace, it's MUI and Emotion packages are being installed in the root node_modules folder. When the Next.js application runs, any MUI hooks or utils that are imported from the workspace's node_modules folder aren't aware of the ThemeProvider context coming from MUI and Emotion in the root node_modules folder. Potentially hacky solution:When I removed MUI and Emotion packages from the individual workspace's package.json files and moved them up to the root package.json file, the problem went away. This is because now when the Next.js app runs, the ThemeProvider context is the same for all MUI hooks, utils and components. It's worth noting that I needed to delete the .next cache in the workspace and re-run the local server to ensure that no cached MUI and Emotion data was being used. Potential downsidesA downside to this could be that now all the workspaces in the monorepo would have to use the same MUI version. This is probably a requirement in this scenario because if the versions varied then MUI or Emotion would be installed in the workspaces's own node_modules folders which would trigger the same error as before. Another downside is the potential confusion this may cause to other developers if they are maintaining or upgrading package versions and it's not clear why the packages have been installed in this way. Another potential solutionAn alternative to manually handling the packages in this way is to pnpm instead of yarn. pnmp has a shamefully-hoist config option which forces a package to be hoisted to the root node_modules folder. Why was Emotion moved to the root package.json too?When I was debugging this issue, I experimented with manually deleting the @mui folder from the workspace's own node_modules folder so that when the project is served locally it uses the @mui folder found in the root node_modules. When I left the emotion folder in the workspace's node_modules folder the TL;DRThe issue in monorepos could be due to MUI and Emotion packages not being hoisted to the root node_modules folder which could be preventing the ThemeProvider context from being shared between workspaces. |
My context is a React application that I'm migrating from webpack to vite, this is one of the errors that I started seeing. I'm still getting other errors, so I can't say for 100%, but I believe the other errors aren't related to this issue. Perhaps this is already fixed? |
Thanks, today I was writing my personal project and inexplicably got
error. When I checked against your troubleshooting steps and changed the " |
this helped me: in vite.config.ts:
second thing that could help: go to third option for solving this issue: upgrade/downgrade |
This resolved issue on my side |
Thank you, this helps!!! |
Thanks
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Jessy Yeh ***@***.***>
Sent: Wednesday, July 10, 2024 1:58:23 PM
To: mui/material-ui ***@***.***>
Cc: Umar Shakoor ***@***.***>; Comment ***@***.***>
Subject: Re: [mui/material-ui] Uncaught TypeError: styled_default is not a function (Issue #36511)
this helped me:
in vite.config.ts:
...pluginsAndOtherStuff,
optimizeDeps: {
include: ***@***.***/material', ***@***.***/react', ***@***.***/styled'],
}
Thank you, this helps!!!
—
Reply to this email directly, view it on GitHub<#36511 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/A77TIDZ5HXII5TS4WOMHLBLZLTZS7AVCNFSM6AAAAAAV2K5SJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJZHE2DMMZYGY>.
You are receiving this because you commented.Message ID: ***@***.***>
|
This resolved issue on my side Thank you so much itbali |
I have solved this issue by updating vite.config.js: optimizeDeps in vite.config.js |
Even though it may not necessarily look like it, we have reason to believe that the root cause of this issue actually lies in If you still run into issues after upgrading to >6.1.0, please open a new ticket, this will allow us to separate whatever problem is left from the rest of this ticket. Thank you for your patience. |
This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Note We value your feedback @Nefcanto! How was your experience with our support team? |
@Janpot how does that help everyone still on v5? |
OK Thankyou |
@Janpot so am i supposed to invest time to migrate to v6 right away in order to be able to run my app....? is there no fix for v5 users? |
Summary 💡
I updated my
package.json
and sometimes I get this error and it's not going away. But sometimes I don't get it.The problem is two-folded:
Examples 🌈
No response
Motivation 🔦
Please add more info to it. Please let us know what have we done wrong to get this error.
I have tried things proposed on StackOverflow and #32727 but none worked for me.
Please give us more info. That's the feature I'm requesting. Thank you.
The text was updated successfully, but these errors were encountered: