You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何使用Material-UI Table报Element type invalid错误,HTML Table及其他场景正常?

Troubleshooting "Element type is invalid" with Material-UI Table

Hey there! Let’s dig into this error you’re facing with the Material-UI Table component. That message—"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined"—is super common when there’s a hiccup in how you’re importing or referencing a component. And since your regular HTML tables work fine + you’ve used MUI components elsewhere without issues, we can narrow down the fixes pretty quickly.

Here are the most likely culprits and how to fix them:

  • Double-check your import statements
    This is the #1 reason for this error. Make sure you’re importing all required Table sub-components correctly from the right MUI package. For MUI v5, your imports should look like this:

    import Table from '@mui/material/Table';
    import TableBody from '@mui/material/TableBody';
    import TableCell from '@mui/material/TableCell';
    import TableContainer from '@mui/material/TableContainer';
    import TableHead from '@mui/material/TableHead';
    import TableRow from '@mui/material/TableRow';
    

    If you’re using MUI v4, swap @mui/material with @material-ui/core. Also, watch out for mixing up default exports (like Table) with named exports—all these sub-components follow consistent export rules, so don’t miss curly braces where they’re needed.

  • Watch for typos in component names
    It’s easy to slip up and write TableHeader instead of TableHead, or TableRows instead of TableRow. Even a tiny typo will result in an undefined component, which triggers this exact error. Go line by line through your commented-out MUI Table code to spot any misspellings.

  • Ensure you’re not referencing an undefined component
    If you’re using a custom wrapper around the MUI Table, double-check that your wrapper component is correctly exported and imported. For example, if you have a CustomTable.js file, make sure it has export default CustomTable; (or a named export) and you’re importing it properly in your parent component.

  • Confirm consistent MUI versions across your app
    If other parts of your app use a different version of Material-UI than the one you’re trying to use for this Table, that could cause import mismatches. Check your package.json to ensure you’re using the same MUI package version everywhere (either v4’s @material-ui/core or v5’s @mui/material).

Since your regular HTML tables work and other MUI components function as expected, the issue is almost certainly isolated to how you’re setting up this specific Table component. Start with verifying your imports and checking for typos—those fixes usually resolve this error right away.

内容的提问来源于stack exchange,提问作者G.Musgrave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:27:57