-
Notifications
You must be signed in to change notification settings - Fork 2.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
Material UI breaks Remix SPA build (but works fine in regular Remix apps) #9632
Comments
This has come up before and I believe the underlying issue is that MUI is not properly configured for ESM/CJS which fails the Remix server build. Even in SPA mode, Remix does a server build so it can render your root component on the server at build time to generate the The best workaround I know of is to put any MUI (or otherwise non-server-friendly code) in your startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<ThemeProvider theme={createTheme(esES)}>
<CssBaseline />
<RemixBrowser />
</ThemeProvider>
</StrictMode>
);
}); |
Thanks a lot, @brophdawg11. That makes sense. |
@brophdawg11 I've been working on this, and even thought the cliend side works fine, this solution means we cannot use the theme in the server. This makes it hard to use MUI to render the I tried
Looking at the package.json definition in
Is there any way to make this work in the server side without bundling material packages via |
From what I understand, MUI needs to fix their published package files and |
why was this closed with no answer? |
Because OP stated
|
Reproduction
Clone https://github.com/npapagna/remix_spa_mui_repro and follow steps to reproduce described in the README.md file.
System Info
Used Package Manager
npm
Expected Behavior
I was expecting
npm run build
to finish successfully.Actual Behavior
Running
npm run build
fails with the following error:Tried using
vite-plugin-cjs-interop
,noExternal
, andserverModuleFormat: 'cjs'
invite.config.ts
to fix this error without success.Notice that even though the file mentioned in the error above (
node_modules/@mui/material/locale/index.js
) does not have a default export (the recommended fix included in the error message doesn't work),npm run build
works fine when I setssr: true
invite.config.ts
.I know this does not make sense in a SPA app, but I found this because I'm trying to migrate the frontend of a regular Remix app to a SPA one (and the frontend code builds just fine in the regular Remix app).
The text was updated successfully, but these errors were encountered: