material-ui: Popper.js:9 Uncaught TypeError: styled_default is not a function
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior šÆ
Popper.js:9 Uncaught TypeError: styled_default is not a function
im not able to run my app

Expected behavior š¤
it should run
Steps to reproduce š¹
Steps: installed mui and try to run with vite
Context š¦
No response
Your environment š
`npx @mui/envinfo`
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
System:
OS: macOS 11.6.2
Binaries:
Node: 14.17.0 - /usr/local/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 6.14.13 - /usr/local/bin/npm
Browsers:
Chrome: 101.0.4951.64
Edge: Not Found
Firefox: Not Found
Safari: 14.1.2
npmPackages:
@emotion/react: ^11.9.0 => 11.9.0
@emotion/styled: ^11.8.1 => 11.8.1
@mui/base: 5.0.0-alpha.80
@mui/icons-material: ^5.6.2 => 5.6.2
@mui/lab: ^5.0.0-alpha.81 => 5.0.0-alpha.81
@mui/material: ^5.8.0 => 5.8.0
@mui/private-classnames: 5.7.0
@mui/private-theming: 5.7.0
@mui/styled-engine: 5.7.0
@mui/styles: ^5.7.0 => 5.7.0
@mui/system: 5.7.0
@mui/types: 7.1.3
@mui/utils: 5.7.0
@mui/x-data-grid: ^5.9.0 => 5.10.0
@mui/x-date-pickers: 5.0.0-alpha.0
@types/react: 18.0.9
react: ^17.0.0 => 17.0.2
react-dom: ^17.0.0 => 17.0.2
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 38
- Comments: 99 (15 by maintainers)
Our team is seeing the same error.
It seems to be:
pnpm pruneor removingnode_modulesfoldersOptimizing
@mui/material/Unstable_Grid2worked for me invite.config.tsšIām having the same problem.
Based on @david-schopf comment I can confirm that changing the imports for just the icons does work around the problem. Youāll notice however that your dev build will be larger (probably doesnāt matter). Your prod build also ends up transforming about 10,000 addition files (every icon in the package, rather than just the ones you used) but itās size seems unaffected. I guess it successfully tree shakes the unused icons.
Based on @dougrday comment I added the following to my
vite.config.tsand it resolves the problem keeping the imports āas isā. (egimport ArrowBackIcon from '@mui/icons-material/ArrowBack';).ps) when messing around with this it pays to use
vite serve --forceto make sure itās not caching anything insidenode_modules/.vite.same problem with vite and npm, all latest versions
I solved it like this
and
./node_modules/.vite <---- delete
Etc ā¦
Delete Vite cache and that would be enough
@denchiklut solution worked for me.
Here is my
vite.config.tsGot the same issue. Already removing node_modules and reinstalling again, but it didnāt work. Happened when using ThemeProvider.
Resolved by export the ThemeProvider properly using
previously
ā@mui/materialā: ā^5.10.0ā āviteā: ā^3.0.5ā
Would be cool to see the amount of dev hours (and money lost) due to this issue
Edit: Using Vite, only
optimizeDepsworked, nothing elseHello eveyone I also have same problem can you please tell me how can i sort this issue . my project is large scale project i can not delete or recreate , i have updated popper.js latest version , i am usgin reactjs with vite
I also had a similar issue. The problem came from calling the MUI
Autocompletecomponent on my React Vite app. I didnāt know why the MUIAutocompletecomponent could trigger theTypeError: styled_default is not a functionfrom thePopper.jsfile. I have solved the problem using the combination of @tiavina-mika and @mikhail-fedosenko answers on thevite.config.jsfile here:Ok please, this issue has been open for 12 months. And a solution or workaround has not been found.
My entire team has ground to a halt due to this issue, and every fix seems to be the luck of the draw. Some solutions have worked for us for a few hours only for it to reappear.
Is there anything I can do to help draw more developer time to this issue, it is really impacting the team.
Thanks itās worked for me, thanks a lot
Is there any update related to the origin of this problem? Itās very unpredictable.
Encontrei a solução, no meu caso, o problema foi o vite, fiz um downgrade para a versão 2.8.6 e o erro sumiu, acredito que existe algum conflito na versão 2.9.0 do vite com o popper.
Adding to
vite.config.tsalso worked:We could get rid of the error by converting all MUI icons imports to this format:
import { FeedbackOutlined } from '@mui/icons-material';instead of` import FeedbackOutlinedIcon from ā@mui/icons-material/FeedbackOutlinedā;We import MUI components directly (
import Button from '@mui/material/Button';) but we import the whole ā@mui/icons-materialā package. That way the error disappeared. Good luck @jacobgadsame problem with vite and npm, all latest versions
But why is this the case? It should work in either instance. Please advice - issue is not resolved. unsure why the thread has been closed.
Happy New Year everyone forget the past and enjoy today life will have lots of errors forget old errors, create new errors
Thank you so much, this worked for me after I donāt even know how many hours of searching and trying - I am gonna post it in the MUI thread as well, lotta folks there still battling with this issue
I was having this issue all of a sudden after adding mui icons to my project. Nothing was fixing it, I kept getting an error about:
Then I remembered I was using Grid2, and applied the change suggested by @samipshresthaq. Updating the import for Grid2 so it was this:
Solved my issue.
This helped me with the problem ⦠I ran ānpm install @mui/systemā and it started working
Update to vite@4 and
@vitejs/plugin-react-swcinstead of@vitejs/plugin-reactsolved my problemThis may likely be a Vite bug (or esbuild) as well. If anyone can reproduce this issue and provide a repo or stackblitz, that would be really helpful here and for https://github.com/vitejs/vite/issues/8308. Otherwise itās hard to take action. (Canāt reproduce the issue from the conversation above)
It is pinned down, https://github.com/evanw/esbuild/issues/3357 is the root cause.
One of the things that triggers the behavior is the mixing of ESM and CJS. At least in my app,
@mui/icons-materialis CJS while@mui/materialis ESM, so I believe https://github.com/mui/material-ui/issues/35233 will incidentally fix it for most people. I have patched thepackage.jsonof my app to use the ESM files in@mui/icons-materialto work around the issue until then.Silly me, I should have checked all the comments from Methuselah96 before doing this, just found out that everything I did has already been done by him. This is probably the bug about unstable code splitting evaluation order which is mentioned in esbuild docs, Vite dev server is fast thanks to esbuild so there is no way to fix this in Vite, if we get this issue we need to fix it via other means.
Well, at least I can rest now knowing that a proper fix does not exist (yet).
I forked a repo from someone else having the same problem and try to trim down the unnecessary details, this is what I came up with: https://github.com/duongdominhchau/mui-bug
I reproduced it successfully locally, then I also upload it to https://stackblitz.com/github/duongdominhchau/mui-bug to verify again, still happens as expected. Itās the same error, but Iām using Firefox so the message is different, ignore that detail.
I used
ncu -u(npm-check-updates) to ensure all these dependencies are up to date. All irrelevant details are removed. Essentially, the problem happens if we mix Box or Grid v2 with@mui/icons-material. Iām on my way trimming it down further, just posting it here early in case someone else is also investigating like me.Update: Immediately after posting this comment, I tried merging the import of
ThemeProviderandcreateTheme(toimport { ThemeProvider, createTheme } from '@mui/material'), the problem disappears!I captured the
node_modules/.vitebefore the problem disappears, here I can see@mui/material/stylesand@mui/materialare bundled separately. Iām on my way inspecting the bundles, this list may be useful laterthis worked for me
For me worked by change the ThemeProvider export path
after
import { ThemeProvider } from '@mui/material/styles';previously
import { ThemeProvider } from '@mui/material';I donāt think the Babel plugin is related. Itās hard to test whether youāve actually fixed the bug since itās caching related, so it doesnāt always show up. It could be that adding the Babel plugin invalidated the Vite cache which may be why it started working after those changes.
Unfortunately adding types to
@mui/icons-material/esmis a no-go. Therefore, I am currently patching thepackage.jsonof@mui/icons-materiallike so:This is similar to https://github.com/mui/material-ui/issues/35233#issuecomment-1696918421, however I donāt think it should have a
"type": "module"since the .js files at the top level shouldnāt be interpreted as ESM by default. I also added a./esm/*.jscondition since I had another dependency that was depending on those to exist.Hopefully this can get resolved, either by esbuild, Vite, or MUI (by adding a way to import from ESM without custom configuration).
Adding
import "@emotion/react"at the top of the entry file helped me. I am not sure but I think it can be somehow related to imports order. I think MUI, requires a specific order for the imports to work properly. The@emotion/reactand@emotion/styledpackages need to be imported before importing@mui/material. But I canāt find confirmation of this in their docs.Or u can try to add this code to your Vite config.
Hereās a blog post that might help some people experiencing this issue out: https://medium.com/@fael.atom/struggling-with-vite-and-mui-42f3f5e0658d
Itās not directly related, but it may lead someone down the rabbit hole that resolves this problem.
Same problem with vite and pnpm, all last versions.
Is there any solution ? I have the same error.
This worked for me:
The only thing that helped me to get unblocked was to go to Popper.js file in node_modules (node_modules/@mui/material/Popper/Popper.js) and then commenting out this code
After that I had to replace
PopperRootwithPopperUnstyledin the same file herePlease note that this solution doesnāt actually fixes the issue, but it will unblock you for the local development.
Same issue
"vite": "^3.1.8"My system is macOS Big Sur MacBook Air M1, node v18.Sadly, the only thing that makes it work for me is removing
node_modulesand then fresh-installing modules WHILE HAVING SOME SYNTAX ERROR IN SOME .tsx FILE 𤯠After that you can remove the syntax error you planted before and everything work. But whatever I do without the installation with self-planted error in the code āĀ it just simply wonāt run properly.UPD. Removing unused package
styled-componentsseems to solve the problem.Got the same issue, what worked for me is removing node_modules and reinstalling dependencies. I assume the issue is related to vite caching system. It goes really fast even for a big project when you are using yarn or pnpm
I was facing same issue and this helps me in getting resolving the issue, as I am using VITE, You can add popper.js in the dependencies array of Vite.
// https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], resolve: { alias: { "@": resolve(__dirname, "src"), }, }, optimizeDeps: { include: ["@mui/material/Tooltip", "@emotion/styled", "@mui/material/Unstable_Grid2", "@tabler/icons-react"], }, });None of these suggestions worked for me, but the babel plugin did. I followed this guide: https://dev.to/glocore/configure-emotion-with-your-vite-react-project-7jl
Which essentially adds the babel plugin to dev dependencies with
and then configures vite
I ran the component tests, and it suddenly works as expected without the
styled_defaulterrors I was seeing previously. Hopefully this helps someone else as wellNote: I DO have this setup for my optimizeDeps as well. Iām not sure if itās making any difference, since the issues still occurred until I added the babel plugin, but its worth mentioning just in case
The issue in this case only occurs when CJS and ESM are mixed. In the projects Iām working on,
@mui/icons-materialis the only CJS that is importing from@mui/materialso switching to@mui/icons-material/esmfixes the issue (also discussed here).The only issue is that
@mui/icons-material/esmdonāt have type definitions, so Iāve opened https://github.com/mui/material-ui/pull/38742 to add type definitions to@mui/icons-material/esm.I have narrowed down the issue a bit and created an issue on esbuild: https://github.com/evanw/esbuild/issues/3357.
After all day fighting,
npm cache clean --forceworked for me šif you have problem with Grid2, you can fix that by mapping dependency alias inside vite config file
resolve: { alias: { "@mui/material/Unstable_Grid2": "@mui/material/Unstable_Grid2/Grid2",For me helped to solve the issue adding an import to the entry file AND assigning the import to a variable (so vite doesnāt remove the unused import):
Note: this issue got fixed for me once i updated all my material imports to : import { KeyboardBackspace} from ā@mui/icons-materialā;
thank you to @david-schopf for your help. I can confirm that changing all the mui icon imports as mentioned:
import { FeedbackOutlined } from '@mui/icons-material';instead ofimport FeedbackOutlinedIcon from '@mui/icons-material/FeedbackOutlined';has permanently fixed the problem for us. I did not need to change the mui imports to direct imports, just changing the icons did the trick.
works for me
Facing the same error. None of the solutions here fix this
Since weāve updated all our packages in
package.jsonweāve no longer encountered this issue. Perhaps itās been fixed as part of another (unrelated) bug fix?Hereās what weāre using - and havenāt seen the errors since:
https://github.com/mayankpandav/demo_mui_vite no luck even not using Button on demo repository @BohdanKov
This error is related to vite, not related to MUI. This kind of error was seen earlier: https://github.com/vitejs/vite/issues/1853 but didnāt find out why this error comes in the latest vite.
Hi, the same error happened to me. I created a branch using an old commit and it worked, but when I tried to downgrade my current branch to the same versions as the old branch it didnāt resolve.
You also clone this repository: https://github.com/mui/material-ui/tree/master/examples/vitejs
You can follow this example: https://stackblitz.com/edit/github-1ta5zk?file=src%2FApp.jsx You need to install peer dependencies
emotion."@emotion/react", "@emotion/styled"