admin管理员组文章数量:1332345
I tried to follow / but I get an error crashing the whole application:
TypeError: Cannot read properties of undefined (reading 'plain')
I am also using Typescript. My files look as follows:
my-project/app/theme.ts -> copied the source
'use client';
import { Roboto } from 'next/font/google';
import { createTheme } from '@mui/material/styles';
const roboto = Roboto({
weight: ['300', '400', '500', '700'],
subsets: ['latin'],
display: 'swap',
});
const theme = createTheme({
typography: {
fontFamily: roboto.style.fontFamily,
},
});
export default theme;
my-project/app/layout.tsx
"use client"
import { Amplify } from "aws-amplify"
import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito"
import { sessionStorage } from "aws-amplify/utils"
import { Suspense } from "react"
import { Provider } from "react-redux"
import { store } from "@data/index"
import amplifyConfig from "@utils/amplifyConfig"
import RequireAuth from "@components/RequireAuth/RequireAuth"
import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter';
import theme from "./theme"
import { ThemeProvider } from "@mui/material/styles";
Amplify.configure(amplifyConfig)
cognitoUserPoolsTokenProvider.setKeyValueStorage(sessionStorage)
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<title>My shitty app</title>
</head>
<body style={{ margin: 0, padding: 0 }}>
<AppRouterCacheProvider>
<ThemeProvider theme={theme}>
<Provider store={store}>
<Suspense>
<RequireAuth>
{children}
</RequireAuth>
</Suspense>
</Provider>
</ThemeProvider>
</AppRouterCacheProvider>
</body>
</html>
)
}
What am I doing wrong? Also I tried upgrading to MUI v6 and it wrecked my entire local dev environment to the point where yarn dev
wouldn't start so I had to git clone again the whole thing... My immediate goal was just to style all the buttons to have border-radius: "20px"
[EDIT]: actually the errors come from @mui/joy which is also used in the project. I guess more work needs to be done to integrate theming with both MUI and Joy. Fair to say this caused me anything but Joy...
I tried to follow https://v5.mui/material-ui/integrations/nextjs/ but I get an error crashing the whole application:
TypeError: Cannot read properties of undefined (reading 'plain')
I am also using Typescript. My files look as follows:
my-project/app/theme.ts -> copied the source
'use client';
import { Roboto } from 'next/font/google';
import { createTheme } from '@mui/material/styles';
const roboto = Roboto({
weight: ['300', '400', '500', '700'],
subsets: ['latin'],
display: 'swap',
});
const theme = createTheme({
typography: {
fontFamily: roboto.style.fontFamily,
},
});
export default theme;
my-project/app/layout.tsx
"use client"
import { Amplify } from "aws-amplify"
import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito"
import { sessionStorage } from "aws-amplify/utils"
import { Suspense } from "react"
import { Provider } from "react-redux"
import { store } from "@data/index"
import amplifyConfig from "@utils/amplifyConfig"
import RequireAuth from "@components/RequireAuth/RequireAuth"
import { AppRouterCacheProvider } from '@mui/material-nextjs/v13-appRouter';
import theme from "./theme"
import { ThemeProvider } from "@mui/material/styles";
Amplify.configure(amplifyConfig)
cognitoUserPoolsTokenProvider.setKeyValueStorage(sessionStorage)
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<title>My shitty app</title>
</head>
<body style={{ margin: 0, padding: 0 }}>
<AppRouterCacheProvider>
<ThemeProvider theme={theme}>
<Provider store={store}>
<Suspense>
<RequireAuth>
{children}
</RequireAuth>
</Suspense>
</Provider>
</ThemeProvider>
</AppRouterCacheProvider>
</body>
</html>
)
}
What am I doing wrong? Also I tried upgrading to MUI v6 and it wrecked my entire local dev environment to the point where yarn dev
wouldn't start so I had to git clone again the whole thing... My immediate goal was just to style all the buttons to have border-radius: "20px"
[EDIT]: actually the errors come from @mui/joy which is also used in the project. I guess more work needs to be done to integrate theming with both MUI and Joy. Fair to say this caused me anything but Joy...
Share Improve this question edited Nov 20, 2024 at 22:04 JustANoob asked Nov 20, 2024 at 21:32 JustANoobJustANoob 1771 gold badge2 silver badges11 bronze badges1 Answer
Reset to default 0Fixed the issue by following these links:
- https://mui/joy-ui/integrations/material-ui/
- https://mui/material-ui/customization/css-theme-variables/usage/
"use client"
import { Amplify } from "aws-amplify"
import { cognitoUserPoolsTokenProvider } from "aws-amplify/auth/cognito"
import { sessionStorage } from "aws-amplify/utils"
import { Suspense } from "react"
import { Provider } from "react-redux"
import { store } from "@data/index"
import amplifyConfig from "@utils/amplifyConfig"
import RequireAuth from "@components/RequireAuth/RequireAuth"
import { AppRouterCacheProvider } from '@mui/material-nextjs/v15-appRouter';
import theme from "./theme"
import {
extendTheme as materialExtendTheme,
ThemeProvider as MaterialThemeProvider,
THEME_ID as MATERIAL_THEME_ID,
} from '@mui/material/styles';
import { ThemeProvider as JoyThemeProvider } from '@mui/joy/styles';
import CssBaseline from '@mui/material/CssBaseline';
Amplify.configure(amplifyConfig)
cognitoUserPoolsTokenProvider.setKeyValueStorage(sessionStorage)
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<title>My Shitty App</title>
</head>
<body style={{ margin: 0, padding: 0 }}>
<AppRouterCacheProvider>
<MaterialThemeProvider theme={{ [MATERIAL_THEME_ID]: theme }}>
<JoyThemeProvider>
<CssBaseline enableColorScheme />
<Provider store={store}>
<Suspense>
<RequireAuth>
{children}
</RequireAuth>
</Suspense>
</Provider>
</JoyThemeProvider>
</MaterialThemeProvider>
</AppRouterCacheProvider>
</body>
</html>
)
}
本文标签: reactjsMaterialUI v5 and Nextjs 14 integration not working with themingStack Overflow
版权声明:本文标题:reactjs - Material-UI v5 and Next.js 14 integration not working with theming - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742326953a2453915.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论