Skip to content
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

MUI React Component Library / Fails in all modes #428

Open
Tracked by #423 ...
aheissenberger opened this issue Jan 26, 2024 · 33 comments
Open
Tracked by #423 ...

MUI React Component Library / Fails in all modes #428

aheissenberger opened this issue Jan 26, 2024 · 33 comments
Labels
help wanted Extra attention is needed

Comments

@aheissenberger
Copy link
Contributor

pnpm waku dev or pnpm waku dev --with-ssr - looks like a problem in ViteJS:

"@mui/material": "^5.15.6",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"vite": "^5.0.12",
"waku": "0.19.1"

Repo to reproduce error:
https://github.com/aheissenberger/waku-mui

Error:

ready: Listening on http://localhost:3000/
22:46:22 [vite] Pre-transform error: [vite] The "code" property of ModuleInfo is not supported.
22:46:23 [vite] Error when evaluating SSR module /src/templates/home-page.tsx: failed to import "/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_reac_6uvakbjdbr4jjappweoxbh4ft4/node_modules/@mui/material/Button/index.js"
|- Error: [vite] The "code" property of ModuleInfo is not supported.
    at Object.get (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:63625:19)
    at load (file:///waku-mui/node_modules/.pnpm/[email protected][email protected][email protected]_gs5p533tfweocikxyqduoft2v4/node_modules/waku/dist/lib/plugins/vite-plugin-rsc-transform.js:45:21)
    at async parseExportNamesInto (file:///waku-mui/node_modules/.pnpm/[email protected][email protected]_t4eugufsfo5omzsdzuea64ykkm/node_modules/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.min.js:222:33)
    at async transformClientModule (file:///waku-mui/node_modules/.pnpm/[email protected][email protected]_t4eugufsfo5omzsdzuea64ykkm/node_modules/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.min.js:282:3)
    at async Module.load (file:///waku-mui/node_modules/.pnpm/[email protected][email protected]_t4eugufsfo5omzsdzuea64ykkm/node_modules/react-server-dom-webpack/esm/react-server-dom-webpack-node-loader.production.min.js:414:20)
    at async TransformContext.transform (file:///waku-mui/node_modules/.pnpm/[email protected][email protected][email protected]_gs5p533tfweocikxyqduoft2v4/node_modules/waku/dist/lib/plugins/vite-plugin-rsc-transform.js:60:30)
    at async Object.transform (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:64063:30)
    at async loadAndTransform (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:49741:29)
    at async instantiateModule (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-9A4-l-43.js:50759:10)

ppm waku build

Error:

pnpm waku build
vite v5.0.12 building SSR bundle for production...
✓ 285 modules transformed.
✓ built in 1.05s
vite v5.0.12 building SSR bundle for production...
✓ 31 modules transformed.
[commonjs--resolver] Duplicate export "default"
file: /waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/GlobalStyles/index.js:3:0
1: 'use client';
2: 
3: export { default } from './GlobalStyles';
   ^
4: export * from './GlobalStyles';
file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:337
        base = Object.assign(new Error(base.message), base);
                             ^

Error [RollupError]: Duplicate export "default"
    at error (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
    at Module.error (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:12781:16)
    at Module.assertUniqueExportName (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13249:18)
    at Module.addExport (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:13255:18)
    at ExportDefaultDeclaration.initialise (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:9569:28)
    at new NodeBase (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:4623:14)
    at new ExportDefaultDeclaration (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:9557:1)
    at Program.parseNode (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:4734:27)
    at new NodeBase (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:4622:14)
    at new Program (file:///waku-mui/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/node-entry.js:11012:9) {
  code: 'PLUGIN_ERROR',
  id: '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/GlobalStyles/index.js',
  pos: 631,
  loc: {
    column: 0,
    file: '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/GlobalStyles/index.js',
    line: 3
  },
  frame: "1: 'use client';\n" +
    '2: \n' +
    "3: export { default } from './GlobalStyles';\n" +
    '   ^\n' +
    "4: export * from './GlobalStyles';",
  pluginCode: 'DUPLICATE_EXPORT',
  plugin: 'commonjs--resolver',
  hook: 'resolveId',
  watchFiles: [
    '/waku-mui/node_modules/.pnpm/[email protected]/node_modules/react/jsx-runtime.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_reac_6uvakbjdbr4jjappweoxbh4ft4/node_modules/@mui/material/Button/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/index.js',
    '/waku-mui/node_modules/.pnpm/[email protected][email protected][email protected]_gs5p533tfweocikxyqduoft2v4/node_modules/waku/dist/client.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_reac_6uvakbjdbr4jjappweoxbh4ft4/node_modules/@mui/material/Button/Button.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useId/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useForkRef/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useEventCallback/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useEnhancedEffect/index.js',
    '/waku-mui/node_modules/.pnpm/[email protected][email protected][email protected]_gs5p533tfweocikxyqduoft2v4/node_modules/waku/dist/router/client.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useEnhancedEffect/useEnhancedEffect.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/usePreviousProps.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useControlled/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useIsFocusVisible.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useForkRef/useForkRef.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useId/useId.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useEventCallback/useEventCallback.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@mui/utils/esm/useControlled/useControlled.js',
    '/waku-mui/node_modules/.pnpm/[email protected][email protected]_t4eugufsfo5omzsdzuea64ykkm/node_modules/react-server-dom-webpack/server.edge.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/GlobalStyles/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@mui/styled-engine/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Box/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/createBox.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/useThemeProps/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/useThemeWithoutDefault.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/ThemeProvider/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Unstable_Grid/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Unstable_Grid/Grid.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_reac_6uvakbjdbr4jjappweoxbh4ft4/node_modules/@mui/material/styles/styled.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Container/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/useTheme.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Stack/Stack.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/GlobalStyles/GlobalStyles.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Stack/index.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Box/Box.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/useThemeProps/useThemeProps.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/ThemeProvider/ThemeProvider.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_react@_vcpncwiim6d7zx7zuiikm6a2vm/node_modules/@mui/system/esm/Container/Container.js',
    '/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]_reac_6uvakbjdbr4jjappweoxbh4ft4/node_modules/@mui/material/styles/defaultTheme.js'
  ]
}
@dai-shi
Copy link
Owner

dai-shi commented Jan 27, 2024

Duplicate export "default" is something I've never seen before.

@dai-shi dai-shi added the help wanted Extra attention is needed label Jan 27, 2024
@dai-shi
Copy link
Owner

dai-shi commented Jan 27, 2024

@Aslemammad any insight?

@Aslemammad
Copy link
Contributor

I'll take a look at this!

@himself65
Copy link
Contributor

Duplicate export "default" is something I've never seen before.

looks like commonjs plugin run twice?

@aheissenberger
Copy link
Contributor Author

no improvement here with #457

@Aslemammad
Copy link
Contributor

taking a look on this.

@Aslemammad
Copy link
Contributor

I'm getting a different error:

8:34:40 PM [vite] Error when evaluating SSR module /src/templates/home-page.tsx: failed to import "@mui/material/Button"
|- TypeError: React__namespace.createContext is not a function
    at Object.<anonymous> (/home/aslemammad/repro/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-element-48d2c2e4.cjs.dev.js:39:59)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/home/aslemammad/repro/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-react.cjs.dev.js:5:22)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

@aheissenberger
Copy link
Contributor Author

With the current main branch and the

I'm getting a different error:

8:34:40 PM [vite] Error when evaluating SSR module /src/templates/home-page.tsx: failed to import "@mui/material/Button"
|- TypeError: React__namespace.createContext is not a function
    at Object.<anonymous> (/home/aslemammad/repro/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-element-48d2c2e4.cjs.dev.js:39:59)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/home/aslemammad/repro/waku-mui/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-react.cjs.dev.js:5:22)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)

This is the error - when using DEV MODE pnpm waku dev --with-ssr

The error Duplicate export "default" is from the BUILD command: pnpm waku build --with-ssr
(I replaced the ssr build target withnode but still got this error.

@Aslemammad
Copy link
Contributor

Yes, I'm trying to fix it! Hope I get the answer to the issue soon.

@Aslemammad
Copy link
Contributor

Well, the dev issue is because emotion/mui are not supporting RSC properly.

emotion-js/emotion#2928
https://mui.com/material-ui/integrations/nextjs/

Let me see the build error now.

@Aslemammad
Copy link
Contributor

The reason for the build error, in many mui modules is that commonjs resolver in rollup seems to have an issue with * exports and default exporting appearing at the same time.

'use client';

export { default } from './Accordion';
export { default as accordionClasses } from './accordionClasses';
export * from './accordionClasses';

I could not find a solution, it'd be interesting to have this reproduced in a vite template without waku or any other module.

I feel I put so much time on finding the answer, but could not, so it might be better to take a time off and put time on the other issues.

@dai-shi
Copy link
Owner

dai-shi commented Feb 19, 2024

So, is it MUI issue?

it might be better to take a time off

okay.

@Aslemammad
Copy link
Contributor

So, is it MUI issue?

Yes, that's how I see it. I might be wrong though.

@dai-shi
Copy link
Owner

dai-shi commented Feb 29, 2024

@aheissenberger Your thought?

@aheissenberger
Copy link
Contributor Author

Currently busy with other projects but I will give it some time and check how it works outside Waku and with NextJS App folder. I won't start before mid of next week.

@oliviertassinari
Copy link

oliviertassinari commented Apr 10, 2024

So, is it MUI issue?

Yes, that's how I see it. I might be wrong though.

What's the issue with Material UI?

@aheissenberger
Copy link
Contributor Author

So, is it MUI issue?

Yes, that's how I see it. I might be wrong though.

What's the issue with Material UI?

I will test it against the current version today and will report the progress.

@aheissenberger
Copy link
Contributor Author

@oliviertassinari MUI 5.15.15 and 6.0.0-alpha.2 are not working with WAKU 0.20.1-alpha.0 in SSR mode.

@oliviertassinari
Copy link

oliviertassinari commented Apr 14, 2024

I mean, what's the root cause? Reading the thread, it seems to be about the way Material UI implements ESM/CJS dual mode support.

@aheissenberger
Copy link
Contributor Author

Yes, a "modern" react library needs to provide code for three different environments during bundling:

  • client - code runs in the browser
  • ssr - code runs in an environment e.g. node or serverlesss edge and needs to produce html for hydration which matches with the client code
  • rsc - code runs in an environment e.g. node or serverlesss edge

Second, MUI and Mantine use a React Context for theming which is not supported on the backend. MUI provides a fix for this with a special RSC Cache for Next.js.

Look at react-textarea-autosize library to see how they bundle and setup the package.json export section to support all modes.

I know MUI 5.15 works with next.js 14 but many library do some kind of rsc/webpack detection which only works with next.js :-(.

@lazarv
Copy link

lazarv commented Jun 26, 2024

I'm investigating these issues in @lazarv/react-server and my results might help you out here too as it's possible that some workarounds work with Waku too.

When I import a MUI component as default, I get a React error about the imported component:

import Button from "@mui/material/Button";

export default function App() {
  return <Button variant="contained">Hello world</Button>;
}
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

This is because the Button import for me is an object like this:

{
  buttonClasses: [Getter],
  default: [Getter],
  getButtonUtilityClass: [Getter]
}

When I'm importing the Button component from the main @mui/material module, it works!

import { Button } from "@mui/material";

export default function App() {
  return <Button variant="contained">Hello world</Button>;
}

Surely this is not ideal, but at least works even with SSR. Based on this finding someone might have a solution for this for the import to work properly, but it seems like some issue with Vite and Material UI, maybe some exports and conditions issue on Material UI's side.

I also tried this out using my ClientOnly component which is just skipping SSR for it's children and only renders children on the client after hydration. Using this works fine in any way, but this is just plain old Vite in that environment.

@dai-shi
Copy link
Owner

dai-shi commented Jun 26, 2024

Thanks!

It seems like we should create a minimal repro again after Waku v0.21 is out. I think I might have a better understanding of the problem and possible solution.

@aheissenberger
Copy link
Contributor Author

I checked with Waku "main" (aa8b021) and MUI "6.0.0-alpha.12". There is a problem with "waku dev" mode.waku build and waku start work without any error with a typical MUI setup:

// _layout.tsx
import type { ReactNode } from 'react';
import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import theme from '../theme.js';
import Button from '@mui/material/Button';

type RootLayoutProps = { children: ReactNode };

export default async function RootLayout({ children }: RootLayoutProps) {
  const data = await getData();

  return (
    <ThemeProvider theme={theme}>
            {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
            <CssBaseline />
    <Button
        variant='contained'
      >
        DEMO
      </Button>
    </ThemeProvider>
    
  );
}

Using MUI without a <ThemeProvider theme={theme}> is not the normal use case and here the real problems is in DEV mode and is similar to Mantine UI Library related to react context used for themes and emotion styles when pre-rendering (SSR) on the server.

pnpm dev  

> [email protected] dev /waku/examples/xx_mui
> waku dev

ready: Listening on http://localhost:3000/
4:53:39 PM [vite] Error when evaluating SSR module /src/pages/_layout.tsx: failed to import "@mui/material/styles"
|- TypeError: React__namespace.createContext is not a function
    at Object.<anonymous> (/waku/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-element-f93e57b0.cjs.dev.js:39:59)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Object..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Function._load (node:internal/modules/cjs/loader:1091:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:212:19)
    at Module.require (node:internal/modules/cjs/loader:1297:12)
    at require (node:internal/modules/helpers:123:16)
    at Object.<anonymous> (/waku/node_modules/.pnpm/@[email protected]_@[email protected][email protected]/node_modules/@emotion/react/dist/emotion-react.cjs.dev.js:5:22)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)


node:internal/event_target:1090
  process.nextTick(() => { throw err; });

@dai-shi
Copy link
Owner

dai-shi commented Jun 26, 2024

I'm working on #709 and it may or may not change something for MUI.

@aheissenberger
Copy link
Contributor Author

Version: WAKU "0.21.0-beta.0" (Commit 06122aa)

Different Error with waku dev - no error when built.

TypeError: __vite_ssr_import_1__.default is not a function
    at Module.createPalette [as default] (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/createPalette.js:265:54)
    at Module.createTheme [as default] (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/createTheme.js:40:48)
    at eval (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/defaultTheme.js:7:51)
    at async instantiateModule (file:///Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:56231:9)
Cannot process SSR TypeError: __vite_ssr_import_1__.default is not a function
    at Module.createPalette [as default] (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/createPalette.js:265:54)
    at Module.createTheme [as default] (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/createTheme.js:40:48)
    at eval (/Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]__@e_l6nifft2jpqrspv7rl42wzb2vi/node_modules/@mui/material/styles/defaultTheme.js:7:51)
    at async instantiateModule (file:///Users/ah/SVN-Checkouts/DEV/waku/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BKbDVx1T.js:56231:9)

@dai-shi
Copy link
Owner

dai-shi commented Jul 2, 2024

If I understand it correctly, adding this in vite.config.ts might help:

export default {
  ssr: {
    optimizeDeps: {
      include: ['...'],
    },
  },
};

@aheissenberger
Copy link
Contributor Author

I added ['@mui/material','@mui/system','@emotion/react','@emotion/styled'] but still get the same error.
And there is not difference in the error with MUI 6.0.0-alpha.13 or stable 5.15.21

@dai-shi
Copy link
Owner

dai-shi commented Jul 2, 2024

ok, my understanding was incorrect.

@Aslemammad when you have time, can you have a look?

dai-shi added a commit that referenced this issue Jul 5, 2024
Hmm, this is going to be a big problem with ESM/CJS compat...

Maybe related: #421, #428
himself65 pushed a commit to himself65/waku that referenced this issue Jul 10, 2024
…hi#779)

Hmm, this is going to be a big problem with ESM/CJS compat...

Maybe related: dai-shi#421, dai-shi#428
@dai-shi
Copy link
Owner

dai-shi commented Sep 21, 2024

Could anyone try the latest version and summarize the issue as of now?

@oliviertassinari
Copy link

oliviertassinari commented Sep 21, 2024

With the latest version of all dependencies:

    "react": "19.0.0-rc-d6cb4e77-20240911",
    "react-dom": "19.0.0-rc-d6cb4e77-20240911",
    "react-server-dom-webpack": "19.0.0-rc-d6cb4e77-20240911",
    "@emotion/react": "11.13.3",
    "@emotion/styled": "11.13.0",
    "@mui/material": "6.1.1",
    "waku": "0.21.2"

and

diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 07f033f..68235c9 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,5 +1,5 @@
 import { Link } from 'waku';
+import Button from '@mui/material/Button';
-
 import { Counter } from '../components/counter';

 export default async function HomePage() {
@@ -11,9 +11,6 @@ export default async function HomePage() {
       <h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1>
       <p>{data.body}</p>
       <Counter />
+      <Button>
+        Button
+      </Button>
       <Link to="/about" className="mt-4 inline-block underline">
         About page
       </Link>

We get this error:

SCR-20240921-dckg

With

diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 07f033f..68235c9 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
@@ -1,5 +1,5 @@
 import { Link } from 'waku';
+import { Button } from '@mui/material';
-
 import { Counter } from '../components/counter';

 export default async function HomePage() {
@@ -11,9 +11,6 @@ export default async function HomePage() {
       <h1 className="text-4xl font-bold tracking-tight">{data.headline}</h1>
       <p>{data.body}</p>
       <Counter />
+      <Button>
+        Button
+      </Button>
       <Link to="/about" className="mt-4 inline-block underline">
         About page
       </Link>

we get this error:

SCR-20240921-ddvz

@dai-shi
Copy link
Owner

dai-shi commented Sep 21, 2024

Thanks for the small reproduction! Yeah, there seems to be a bug somewhere.

@dai-shi
Copy link
Owner

dai-shi commented Sep 21, 2024

For the first case, if I disable "ssr",
https://github.com/dai-shi/waku/blob/58d957c2b6f0e2d01190eb7bfd5d83c05e5dad92/examples/05_nossr/waku.config.ts
This would fix:

// vite.config.ts
export default {                                        
  optimizeDeps: {
    include: [               
      "@mui/utils",                            
      "prop-types",
      "hoist-non-react-statics",
      "react-is",     
    ],                   
  },
}; 

Still investigating with the "ssr" usage.

@dai-shi
Copy link
Owner

dai-shi commented Oct 1, 2024

Did some more investigation with "ssr".
It's due to Waku's behavior, but we import Button.js directly (because it has use client) in "ssr".
However, Button.js isn't marked as ESM, we can't load it:

(node:38535) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

I added "type": "module" manually to node_modules/@mui/material/Button/package.json which leads another error:

Directory import '.../node_modules/@mui/utils/resolveProps' is not supported resolving ES modules imported from .../node_modules/@mui/material/Button/Button.js
Did you mean to import @mui/utils/resolveProps/index.js?

So, I added this to node_modules/@mui/utils/package.json:

  "exports": {
    ".": {
      "import": "./esm/index.js",
      "default": "./index.js"
    },
    "./*": {
      "import": "./esm/*/index.js",
      "default": "./*/index.js"
    }
  },

Now, I get the same error for @mui/system/colorManipulator.

This seems like an endless game. Only the solution from our end would be to avoid using import() at all for DEV. (This is what @Aslemammad was suggesting.)
It would come with some difficulties which we'd avoid for now, so I hope "True ESM support" will come.


In the meantime, this small reproduction works flawlessly with PRD (npm run build && npm start). Would anyone like to try with a bigger example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants