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: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object #63394

Closed
jrjake opened this issue Mar 18, 2024 · 9 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@jrjake
Copy link

jrjake commented Mar 18, 2024

Link to the code that reproduces this issue

https://github.com/jrjake/nextjs-mui-bug

To Reproduce

  1. Use my repo (or any MUI project)
  2. Ensure package.json has "type": "module"
  3. Use MUI component in layout.js. Ensure MUI is 1.15.13, it is not broken in 1.15.5.
  4. You will get "Internal error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object." when running npm run dev.

Current vs. Expected behavior

This was working with Nextjs 14.1.3 and MUI 1.15.5, but I recently tried upgrading to MUI 1.15.13 and got this strange error.

When I console.log(the component), I get {} when "type": "module", but I get [Function (anonymous)] as expected when running without "type": "module".

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Wed Mar  6 19:35:04 UTC 2024
Binaries:
  Node: 20.10.0
  npm: 10.2.3
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: N/A
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

@jrjake jrjake added the bug Issue was opened via the bug report template. label Mar 18, 2024
@ariannargesi
Copy link
Contributor

ariannargesi commented Mar 18, 2024

The repository is empty. Please push your code into it @jrjake

@jrjake
Copy link
Author

jrjake commented Mar 18, 2024

The repository is empty. Please push your code into it @jrjake

Yep, my mistake! I've pushed the code up now.

@Tosinkoa
Copy link

If anyone is facing this error, a fix I found for it is:

Change how you import material ui package from this:
import PieChartIcon from '@mui/icons-material/PieChart'

To this:
import { PieChart } from '@mui/icons-material'

@Wei102193
Copy link

its fixed in 14.3.0-canary.9. #64518 (comment)

@jrjake
Copy link
Author

jrjake commented May 12, 2024

its fixed in 14.3.0-canary.9. #64518 (comment)

Apologies for delay in response, I can confirm this is fixed with that canary build.

Does anyone know if this specific fix will be backported to 14.2.x? I tried testing with a more recent 14.3.0 canary but it appeared to be using React 19 beta, and I'm guessing that will delay 14.3.0 release for a decent while. I also believe Material UI has not added/claimed support for React 19, which will likely delay my ability to use them together for even longer.

@khuezy
Copy link
Contributor

khuezy commented May 15, 2024

Looks like the latest canary reintroduced the error, cc @huozhi

@huozhi
Copy link
Member

huozhi commented May 29, 2024

This should be fixed with latest 14.2.x, please upgrade to 14.2.3

@huozhi huozhi closed this as completed May 29, 2024
@jrjake

This comment has been minimized.

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

6 participants