Open Nefcanto opened 1 year ago
A fresh clone of this reproduction do reproduce this error, but if I remove the node_modules
sometimes the problem will be fixed.
I see that the cause of this issue and #8308 is missing module initialization.
I replace src/main.jsx
with the following content
import { Popper } from "@mui/material";
console.log(Popper);
The Proper
here is mui-material/src/Popper/Popper.tsx
// ...
import { styled, Theme, useThemeProps } from '../styles';
// ...
const PopperRoot = styled(PopperUnstyled, {
name: 'MuiPopper',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
// ...
Full transformed code by vite:
The styled
here is mui-material/src/styles/styled.js
import { createStyled, shouldForwardProp } from '@mui/system';
import defaultTheme from './defaultTheme';
export const rootShouldForwardProp = (prop) => shouldForwardProp(prop) && prop !== 'classes';
export const slotShouldForwardProp = shouldForwardProp;
const styled = createStyled({
defaultTheme,
rootShouldForwardProp,
});
export default styled;
Full transformed code by vite:
Note that in the styled
module, styled
need to be initialized by createStyled
:
// node_modules/@mui/material/styles/styled.js
var rootShouldForwardProp, slotShouldForwardProp, styled, styled_default;
var init_styled = __esm({
"node_modules/@mui/material/styles/styled.js"() {
init_esm();
init_defaultTheme();
rootShouldForwardProp = (prop) => shouldForwardProp(prop) && prop !== "classes";
slotShouldForwardProp = shouldForwardProp;
styled = createStyled({
defaultTheme: defaultTheme_default,
rootShouldForwardProp
});
styled_default = styled;
}
});
export {
useThemeProps2 as useThemeProps,
init_useThemeProps,
rootShouldForwardProp,
slotShouldForwardProp,
styled_default,
init_styled
};
This suggest we should call init_styled
prior to access styled_default
. But such an assertion is failing in Popper
:
import {
PopperUnstyled_default,
init_PopperUnstyled
} from "/node_modules/.vite/deps/chunk-73GXGH6W.js?v=b24550c9";
import {
styled_default,
useThemeProps
} from "/node_modules/.vite/deps/chunk-QGFUN55Y.js?v=b24550c9";
import {
init_esm as init_esm2,
useThemeWithoutDefault_default
} from "/node_modules/.vite/deps/chunk-M6YZV643.js?v=b24550c9";
import {
_objectWithoutPropertiesLoose,
init_objectWithoutPropertiesLoose
} from "/node_modules/.vite/deps/chunk-KBFHYFJ6.js?v=b24550c9";
import {
HTMLElementType,
init_esm,
refType_default
} from "/node_modules/.vite/deps/chunk-KQS6UZBQ.js?v=b24550c9";
import {
require_prop_types
} from "/node_modules/.vite/deps/chunk-EOOR7TYC.js?v=b24550c9";
import {
require_jsx_runtime
} from "/node_modules/.vite/deps/chunk-TNQUW4IY.js?v=b24550c9";
import {
_extends,
init_extends
} from "/node_modules/.vite/deps/chunk-6K2CSZVE.js?v=b24550c9";
import {
require_react
} from "/node_modules/.vite/deps/chunk-JFTBQ7A7.js?v=b24550c9";
import {
__toESM
} from "/node_modules/.vite/deps/chunk-AC2VUBZ6.js?v=b24550c9";
// node_modules/@mui/material/Popper/Popper.js
init_extends();
init_objectWithoutPropertiesLoose();
init_PopperUnstyled();
init_esm2();
init_esm();
var import_prop_types = __toESM(require_prop_types());
var React = __toESM(require_react());
var import_jsx_runtime = __toESM(require_jsx_runtime());
var _excluded = ["components", "componentsProps", "slots", "slotProps"];
var PopperRoot = styled_default(PopperUnstyled_default, {
name: "MuiPopper",
slot: "Root",
overridesResolver: (props, styles) => styles.root
})({});
Missing calling of init_styled
from chunk-QGFUN55Y.js
(the chunk of styled
)
import {
styled_default,
useThemeProps
// init_styled missing
} from "/node_modules/.vite/deps/chunk-QGFUN55Y.js?v=b24550c9";
// missing calling of init_styled();
// styled_default is undefined.
var PopperRoot = styled_default(/* */)
This can be verified using
import("http://localhost:5173/node_modules/.vite/deps/chunk-QGFUN55Y.js?v=b24550c9").then(module =>{
console.log(module.styled_default)
module.init_styled();
console.log(module.styled_default)
})
I think this bug may related to chunk seperation. When such a small chunk of styled
is generated, this bug will occur. When a big chunk like the whole @mui/material
, the initialization will be correct because they have been merged:
node_modules/.vite/deps/@mui_material.js
(Whole big dep chunk of @mui/material
)
// at line number 33000-ish
// node_modules/@mui/material/styles/styled.js
var rootShouldForwardProp = (prop) => shouldForwardProp(prop) && prop !== "classes";
var slotShouldForwardProp = shouldForwardProp;
var styled3 = createStyled3({
defaultTheme: defaultTheme_default,
rootShouldForwardProp
});
var styled_default2 = styled3;
So this comment is true on the aspects of this issue
It seems to be:
- Related to using Vite.
- Intermittent, the problem comes and goes.
- Resolved (sometimes) by
pnpm prune
or removingnode_modules
folders
node_modules
and triggers vite to re-generate deps. Vite seems to be more likely to generate big dep chunks after the first generation. So when people installing/uninstalling deps, this issue tends to be "fixed".Hello, for information, I am facing the same problem when using the Card
component.
@Tanimodori thank you for spending time on this. So it's a Vite bug. I'm glad that you could find the bug. It was such a complicated situation.
Maybe related: #5142
I would like to work on this @Tanimodori @Nefcanto
@ashutosh887 please stop sending these messages to each issue or we will need to ban you from the org
I'm sorry @patak-dev Won't repeat it I'm just willing to contribute
That's great! You are welcome to help. But please avoid generating notifications to all the folks involved in the issues and maintainers. You can read our Contributing guide and pick any open issue. Thanks!
Hey all, I've been trying to fix what I believe is a very similar issue, except for me it affects the @mui/x-date-pickers
.
I'm having the error Uncaught TypeError: useEnhancedEffect_default is not a function
only when building the app
What leads me to believe the issue is related is because of this issue in the mui repo: https://github.com/mui/material-ui/issues/31835 which seems similar to what is described here
While working on a minimal reproduction, it seems like the bug exists in version 4.0.0
of vite, but is resolved in 4.2.0
Please find an attached repository example: https://github.com/jbsouvestre/vite-esbuild-bug-repro There's 2 branches, master is on vite@4.2.0, the production build doesn't have the error
The vite-4.0.0 branch has the bug
If the issue is not related, please disregard this comment
@jbsouvestre The vite version I used for my analysis is 4.2.0 fyi.
I'm also having this issue (on Box.js with the following error : Uncaught TypeError: createTheme_default is not a function
)
I suspect an issue with small chunks since no problem with building the app, and what solved it for me was to change the import of my MUi components as indicated in the comment https://github.com/mui/material-ui/issues/31835#issuecomment-1496428363
I'm having the same issue but with Grid2
Uncaught TypeError: styled_default is not a function
at Grid2.js:5:26
(anonymous) @ Grid2.js:5
Update: I managed to have the error moved onto Box.js as mentioned in the comment above when I rearranged import order.
I was finally successful in removing the error altogether after further import order rearrangements. I essentially started at my top-level app file and moved a few (not all) material component imports to the top. It seemed to like it when custom components that also use MUI components were imported after MUI components used in the immediate file.
Luckily, I didn't have to continue that process into other files as my fix was in a top level file.
Same Issue with Grid2
But caused by upgrading "@mui/x-data-grid" to 6.1.0. The bug doesn't happen on 5.x versions;
id2.js:5 Uncaught TypeError: styled_default is not a function at Grid2.js:5:26 (
Update: I removed @mui/x-data-grid, and the app run; When I put it back, without any reference - only in package.json/yarn.lock, the bug came back. So, isn't seems to be the order of imports.
I had the popper.js
error but it has disappeared after upgrading Vite from 4.1.1 to 4.3.1.
edit: it's back. This issue is popping up daily for at least someone on my team.
edit again: I got rid of <Popper>
in our codebase and replaced it with <Modal>
.
We're also experiencing this issue. Upgrading Vite hasn't worked. It mostly seems to effect us when using icons from the @mui/icons-material
package, but haven't figured out a pattern yet as we use icons all over the place and some seem to work and some don't.
hello i have the same problem here : I even didnt' use popper ! please any help ?
Same problem here, I cant use popper, getting the error:
caught TypeError: styled_default is not a function
at Popper.js:11:20
I'm using vite, npm and styled-components.
Has anyone had any success with a temporary work around? Im using NX and Vite@4.1.1 and this has been a blocker for the past 4 days.
Using Vite v4.3.3 MUI v5.12 @mui/x-data-grid-pro v6
Also having same issue in Grid2.js
Uncaught TypeError: styled_default is not a function
at Grid2.js:5:26
(anonymous) @ Grid2.js:5
Seems to happen after a few restart cycles, usually clearing node_modules and npm install makes it go away for a while but not a great solution.
Was there some logic to the re-ordering of imports that seems to work? Moving Mui imports higher doesnt seem to have any effect for me
I upgraded to notistack v3.x I started to get the same error:
Uncaught TypeError: styled_default is not a function
at Grid2.js:5:26
When fall back to notistack 2.0.8 it goes away.
vite 4.3.3 vitejs/plugin-react-swc 3.3.0 mui 5.12.1 mui/x-data-grid-premium 6.2.1
We encounter the same problem on our project. And we are not able to reproduce systematically the error. We already try to upgrade or downgrade MUI, we check every import. Everything seems right, but sometimes, the appears, sometimes it works perfectly.
I have the same Issue after updating only vite-plugin-checker from 0.5.6 to 0.6.0 Same happens if I only update @vitejs/plugin-react from 3.1.0 to 4.0.0
Uncaught TypeError: styled_default is not a function
at Popper.js:11:20
It doesn't seem related to vitejs version since we have same issue with vite 3.1.0 However, I've the feeling that I might bundling two versions of emotion/styled since @mui has a peer depency on emotion/styled 11.3.0 and x-date-pickers has a peer dependency on emotion/styled 11.8.1
Could it be the issue ?
@nzhiti we don't use x-date-pickers. But I guess every MUI component has a peer dependency to "@emotion/styled": ^11.3.0. We fixed the Version of @emotion/styled to 11.10.6 and still have this issue.
When this error happens, I can observe in the dev tools that many ts(x) files are fetched at once, quite a bunch more than normal.
Same problem here, I cant use popper, getting the error:
caught TypeError: styled_default is not a function at Popper.js:11:20
I'm using vite, npm and styled-components.
Note: I got this error when I tried to use the Popper component from mui that uses Popper js, I didnt had problems when using another components from MUI.
@mtgeddes
how did you rearrangement the import order? I also same issue with Grid2 but I cannot find the correct import order.
how did you rearrangement the import order? I also same issue with Grid2 but I cannot find the correct import order.
Not @mtgeddes but my 2 cents
I tried a lot of things such as updating most of my dependencies, changing all MUI imports to be from only @mui/material
e.g. changing imports from @mui/system
, and adding a alias resolution from @material-ui/icons
to @material-ui/icons/esm
.
At the end I added an eslint plugin to sort my imports based on it's own logic and this fixed my issues. I never investigated why, but maybe it had to do with local project modules being imported before MUI in some key files.
I can reproduce the issue at 100%, in my case (in my project, not sure its the case for all i'm gonna try with a codepen)
import { alpha, createTheme, darken, ThemeProvider as MUIThemeProvider, useTheme as useMUITheme, } from "@mui/material/styles";
instead of
import { alpha, createTheme, darken, ThemeProvider as MUIThemeProvider, useTheme as useMUITheme, } from "@mui/material";
When bug occurs I'm fixing the import, removing node_modules folder and npm install again and then bug disapears.
@mtgeddes
how did you rearrangement the import order? I also same issue with Grid2 but I cannot find the correct import order.
So my process was far from ideal but I just started at my root file and began rearranging imports ... i.e. take whatever is a top and move down a level, save, see if anything changed. I knew this didn't account for cached builds or any potential needs to reinstall node_modules but I just wanted to see if I could get any other errors that might help outline the problem.
I was lucky that it didn't take long to solve my issue. I didn't dig further but as mentioned what I noticed is that it seemed to like when I imported pure mui components before other custom built components that also used pure mui components.
Some of the other temporary solutions above also seem like good solutions to try.
So I managed to remove bug in all my react application this way :
I modified all my import like mentionned in this comment https://github.com/mui/material-ui/issues/31835#issuecomment-1496428363.
I did the same with material icons
import { LocalOffer as LocalOfferIcon } from "@mui/icons-material";
instead of
import LocalOfferIcon from "@mui/icons-material/LocalOffer";
Then I remove node_modules and npm install again.
I can reproduce bug doing again a wrong import again, especially with materials icons importe
Exactly the same problem here! Some update on this?
This has worked for us. https://github.com/mui/material-ui/issues/32727#issuecomment-1553100858
I ran into this issue, though it appeared to have a slightly different cause than others.
I (unintentionally) had a mixture of imports from mdi-material-ui
and @mui/icons-material
. For one reason or another, this led to the same error message from popper.js
. Removing mdi-material-ui
entirely solved the problem in my case.
This has worked for us. mui/material-ui#32727 (comment)
This worked for me as well.
Basically if you have issues with Popper.js
add to vite.config.js
optimizeDeps: {
include: ['@mui/material/Tooltip'],
};
If it's not Popper.js find the relevant component and include it as an optimized dep.
I've also had a similar problem specifically when using @mui/icons-material
as a couple others have mentioned. I have a reproduction here: https://github.com/moribvndvs/vite-mui-material-icon-issues
Changing import NavigateNextIcon from '@mui/icons-material/NavigateNext'
to import {NavigateNext as NavigateNextIcon} from '@mui/icons-material'
(and deleting node_modules/.vite
before restarting the server) fixes that problem, but then I run into a new issue specifically on Firefox (which may be related to #12016 and thus a bug in Firefox).
I am also facing same issue Popper.js:11 Uncaught TypeError: styled_default is not a function at Popper.js:11:20 (anonymous) @ Popper.js:11
Can reproduce "consistently" with https://github.com/vitejs/vite/issues/12423#issuecomment-1678557859. By consistently I mean, running the following command several times in a row, sometimes the problem manifests itself, sometimes it doesn't:
rm -rf node_modules/.vite && yarn dev
One thing that I noticed is that the optimized dependencies folder contains different output for every run. i.e. running the following commands show a diff every time, even between two "good runs":
rm -rf node_modules/.vite && yarn vite optimize --force
rm -rf _vitedeps && cp -r node_modules/.vite/deps _vitedeps
rm -rf node_modules/.vite && yarn vite optimize --force
diff -bur _vitedeps ./node_modules/.vite/deps
Surely two consecutive runs of yarn vite optimize --force
should produce identical output?
I had to downgrade to @mui/x-data-grid-premium@5.17.26 in order to make this work again. As soon as I would upgrade to 6.0.0, the problem was back again. Something about MUI v6 and Vite does not get along at all.
@Tanimodori Thanks for the excellent investigation work.
I've narrowed down the issue a bit more and created an esbuild issue: https://github.com/evanw/esbuild/issues/3357.
This error happened to me after that I updated npm and then fixed it
This has worked for us. mui/material-ui#32727 (comment)
This worked for me as well.
Basically if you have issues with Popper.js
add to vite.config.js
optimizeDeps: { include: ['@mui/material/Tooltip'], };
If it's not Popper.js find the relevant component and include it as an optimized dep.
oh, this is saved my day!
Almost a year and the issue is still there...Can't work.
Thaks for your reply
On Mon, 11 Mar 2024, 15:44 Thomas Tridon, @.***> wrote:
Almost a year and the issue is still there...Can't work.
— Reply to this email directly, view it on GitHub https://github.com/vitejs/vite/issues/12423#issuecomment-1988250194, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUIUBQERMYPPUKEC4O4MH73YXWKIJAVCNFSM6AAAAAAV3NV7GGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGI2TAMJZGQ . You are receiving this because you commented.Message ID: @.***>
Almost a year and the issue is still there...Can't work.
I have the same error and when I get it I can only solve the problem by deleting node_modules and running npm install again.
Because the issue is with the cached dependencies built by esbuild, deleting node_modules/.vite
instead of all of node_modules
may also work, which would make it so that you don't have to run npm install
again.
Because the issue is with the cached dependencies built by esbuild, deleting
node_modules/.vite
instead of all ofnode_modules
may also work, which would make it so that you don't have to runnpm install
again.
Thanks. I followed the recommendation above of adding this to vite.config.js
optimizeDeps: { include: ['@mui/material/Tooltip'], };
and it seems to have done the trick - not sure if this is permanently fixed or just by chance.
I encountered the same error and resolved it by installing 'esbuild'.
You can try this command: 'npm install --save-exact --save-dev esbuild'
Describe the bug
I have updated some of my dependencies.
I expect to see the address of my code in the error call stack.
All I see is this:
I have also reported it to the MUI Team
I have also seen that it's been asked here.
My problem is that the error does not give us more information. Is it a Vite bug? Is it a bug related to esbuild? Is it a bug of MUI? I literally do not know.
Reproduction
https://github.com/Nefcanto/MuiPopperBug
Steps to reproduce
git clone https://github.com/Nefcanto/MuiPopperBug
cd MuiPopperBug
npm install
npm run dev
System Info
Used Package Manager
npm
Logs
No response
Validations