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

[material-ui] Not able to build the project when updating to Next.js 14.2.2 with v5.15.15 #41960

Closed
Heet-Bhalodiya opened this issue Apr 19, 2024 · 5 comments
Assignees
Labels

Comments

@Heet-Bhalodiya
Copy link

Heet-Bhalodiya commented Apr 19, 2024

Steps to reproduce

Link to live example: https://codesandbox.io/p/devbox/fragrant-architecture-xjjj78?file=%2Fapp%2Fpage.tsx%3A6%2C12

Steps:

  1. Start a next project with npx create-next-app@latest
  2. Add MUI by running npm install @mui/material @emotion/react @emotion/styled command
  3. Implement MUI components in the Next.js project.

Current behavior

The basic NextJS project runs fine after initial setup. However, after integrating MUI and using its components, the project still operates normally in development mode. But, when I build the project, I receive the following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object

Using use client with MUI components allows the project to build and run without errors.

I am using NextJS v14.2.2 version and v5.15.15 of MUI.

Expected behavior

After updating MUI and NextJS the above issue is happening.

The components should function correctly after a build, without needing to use use client, similar to how they did in previous versions.

Context

No response

Your environment

npx @mui/envinfo
System:
    OS: macOS 13.2.1
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
    pnpm: 8.11.0 - ~/.nvm/versions/node/v20.9.0/bin/pnpm
  Browsers:
    Chrome: 123.0.6312.124
    Edge: Not Found
    Safari: 16.3
  npmPackages:
    @emotion/react: ^11.11.4 => 11.11.4 
    @emotion/styled: ^11.11.5 => 11.11.5 
    @mui/base:  5.0.0-beta.40 
    @mui/core-downloads-tracker:  5.15.15 
    @mui/material: ^5.15.15 => 5.15.15 
    @mui/private-theming:  5.15.14 
    @mui/styled-engine:  5.15.14 
    @mui/system:  5.15.15 
    @mui/types:  7.2.14 
    @mui/utils:  5.15.14 
    @types/react: ^18 => 18.2.79 
    react: ^18 => 18.2.0 
    react-dom: ^18 => 18.2.0 
    typescript: ^5 => 5.4.5 

Search keywords: NextJS, MUI, Element type is invalid, build, use client

@Heet-Bhalodiya Heet-Bhalodiya added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 19, 2024
@Juneezee
Copy link
Contributor

Duplicate of #41865.

Use import { Typography } from "@mui/material" instead of import Typography from "@mui/material/Typography".

@Heet-Bhalodiya
Copy link
Author

Hi @Juneezee,

Thanks for the quick reply.

import Typography from "@mui/material/Typography" is working perfectly in previous versions of MUI and NextJS. Also I have used this method in my whole project so it is not feasible for me to replace all the imports.

@Juneezee
Copy link
Contributor

@Heet-Bhalodiya In that case, I think you'll have to downgrade to Next.js 14.1.4 for now. See vercel/next.js#64467 (comment) too.

@danielgwilson
Copy link

@Heet-Bhalodiya In that case, I think you'll have to downgrade to Next.js 14.1.4 for now. See vercel/next.js#64467 (comment) too.

This was huge, thank you—fixed the most frustrating build bug with createTheme() I was having

The example project doesn't seem to run either (broken by 14.2.X)

https://github.com/mui/material-ui/tree/next/examples/material-ui-nextjs-ts

@danilo-leal danilo-leal changed the title Not able to build the project when updating to NextJS 14.2.2 with MUI 5.15.15 [material-ui] Not able to build the project when updating to Next.js 14.2.2 with v5.15.15 Apr 22, 2024
@Heet-Bhalodiya
Copy link
Author

Hey Team,

The fix is published in the NextJS v14.2.3.

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants