You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add mui to pages/index/index.page.tsx (in l. 2 and l.9)
import { Counter } from './Counter'
import MenuIcon from '@mui/icons-material/Menu'; // add this
export { Page }
function Page() {
return (
<>
<MenuIcon /> // and this
<h1>Welcome</h1>
This page is:
<ul>
<li>Rendered to HTML.</li>
<li>
Interactive. <Counter />
</li>
</ul>
</>
)
}
Current behavior 馃槸
yarn dev works, yarn prod will throw runtime error when navigating to localhost:3000:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
to vite.config.ts. Unfortunately now yarn dev is broken:
7:13:10 PM [vite] Error when evaluating SSR module /node_modules/@mui/icons-material/Menu.js:
|- TypeError: require is not a function
What is going on here? It should work in production the same as in dev?
It is possible to do a different "fix" (via named imports):
In pages/index/index.page.tsx change import MenuIcon from '@mui/icons-material/Menu'; to import { Menu as MenuIcon } from '@mui/icons-material'; In this case, even ssr: {noExternal: ["@mui/material", "@mui/utils", "@mui/base", "@mui/icons-material"]}, is not needed. It works in dev and prod. Problem is, my machine is running out of memory then, so this "fix" is not possible. Also this should not be done, see Mui guide.
Expected behavior 馃
Mui should behave the same in dev and production. I also checked with the vps maintainer on his repo. It might be, that there is a publishing issue with mui.
Duplicates
Latest version
Steps to reproduce 馃暪
I'm using vite-plugin-ssr, but the error should be the same with different tools. Reproduce error:
yarn create vite-plugin-ssr
-> react-tscd vite-ssr-project/
yarn add @mui/material @emotion/react @emotion/styled @mui/icons-material
Add mui to
pages/index/index.page.tsx
(in l. 2 and l.9)Current behavior 馃槸
yarn dev
works,yarn prod
will throw runtime error when navigating tolocalhost:3000
:Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
This error can be "fixed" by adding
to
vite.config.ts
. Unfortunately nowyarn dev
is broken:What is going on here? It should work in production the same as in dev?
It is possible to do a different "fix" (via named imports):
In
pages/index/index.page.tsx
changeimport MenuIcon from '@mui/icons-material/Menu';
toimport { Menu as MenuIcon } from '@mui/icons-material';
In this case, evenssr: {noExternal: ["@mui/material", "@mui/utils", "@mui/base", "@mui/icons-material"]},
is not needed. It works indev
andprod
. Problem is, my machine is running out of memory then, so this "fix" is not possible. Also this should not be done, see Mui guide.Expected behavior 馃
Mui should behave the same in dev and production. I also checked with the vps maintainer on his repo. It might be, that there is a publishing issue with mui.
Context 馃敠
How to fix this best?
Your environment 馃寧
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: