React MUI 按钮失败,因为未定义元素类型

React MUI Buttons are failing because element type is not defined

我正在为我的项目使用 MUI Buttons,当我渲染一个按钮时它总是抛出这个错误,它工作正常但突然开始抛出它:

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

调试它我看到由于某种原因,MUI 创建的按钮元素没有特定的 属性 React 用来检查它需要加载的元素的类型,特别是 $$typeof.

这是我的代码:

import React, { useState } from 'react';
import {
    useMutation,
    useQueryClient
} from 'react-query';
import { Link as RouterLink } from 'react-router-dom';

import Archive from '@mui/icons-material/Archive';
import Edit from '@mui/icons-material/Edit';
import Unarchive from '@mui/icons-material/Unarchive';
import LoadingButton from '@mui/lab/LoadingButton';
import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';
import IconButton from '@mui/material/IconButton';


const MyComponent = () => {
    return (
    <Grid container item xs={8} justifyContent="flex-end" alignItems="center">
         <IconButton onClick={() => setEditDialogOpen(true)} aria-label="edit">
             <Edit />
         </IconButton>
    </Grid>
    );
}

当 React 试图找出组件的类型时它失败了,因为由于某种原因该类型没有 属性 $$typeof 而它只有一个空对象 属性 称为 default.

这是什么原因造成的?

找到了解决方案,原来我的 package.json 使用 "type": "module" 当我删除它时它按预期工作。

如果我在 emotionjs 中使用类型“module”,似乎会出现问题。我需要修改我的几个文件以适应像我的 jest.config.js 和我的 .eslintrc.js.

这样的变化