-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
When using the latest version of MUI in Astro, it prompts that "require is not defined" #42848
Comments
Hey @cpxGithub, thanks for the report! You mentioned that this worked on |
Version 5.15.11 stopped working |
Might be related to this change: v5.15.10...v5.15.11#diff-9446ee1698c37d364b00d92c4ad52112e927a41211b65bd288d0ee193e3f14aaL55. As the On the sandbox shared, I cannot make it work even with @cpxGithub may I ask you to share a working example with |
Sorry, it was my mistake. I added extra code to the example. Now I have fixed the example and set the version to 5.14.20. New example address: https://stackblitz.com/edit/github-habvmy-ftgbpk?file=package.json |
@michaldudak may I ask for your help here? The example works with I see a couple of PRs that might be related:
But I wonder if those are the cause or not, or if there might be another suspicious change. Related docs:
|
Looking briefly at it, I doubt that it has anything to do with Babel macros. We use them only in development and they are not a part of the resulting bundle. I'll keep investigating it further. |
Thanks for taking a look 👌🏼 If none of those two PRs are related, then I don't know which
|
The main difference between this project using 5.15.10 and 5.15.11 is in node_modules/.vite/deps/@mui_material.js. Specifically, some of the imports come from the The most suspicious change related to @mui/system is changing all the named root imports ( |
@michaldudak thanks fro looking into it, the explanation makes sense. In v5, |
@cpxGithub, Sorry for the delay; this also seems like a CJS/ESM interoperability issue. You can fix it with this config: export default defineConfig({
output: 'server',
integrations: [react()],
vite: {
resolve: {
alias: {
// alias icons to their ESM version
'@mui/icons-material': '@mui/icons-material/esm',
},
},
ssr: {
noExternal: /@mui\/.*?/,
},
},
}); Here's the sandbox working: https://stackblitz.com/edit/github-habvmy-7bff2d?file=astro.config.mjs This should no longer be necessary once #35233 is completed. Does this solve your issue? |
Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information. |
Steps to reproduce
Link to live example: (required) https://stackblitz.com/edit/github-habvmy?file=src%2Fcomponents%2FCounter.tsx
Steps:
1.Create an Astro React project via
pnpm create astro@latest --template framework-react
2.Use the command
pnpm add @mui/material @emotion/react @emotion/styled
to install MUI3.Add Button component in Counter.tsx file
4.Add the following configuration in the astro.config.mjs file
5.Run
pnpm dev
, and the following error message appears in the terminal.6.Modify "@mui/material": "^5.15.21" to "@mui/material": "5.14.20" to run normally
Current behavior
Expected behavior
No response
Context
No response
Your environment
npx @mui/envinfo
Astro info
Search keywords: astro
The text was updated successfully, but these errors were encountered: