【发布时间】:2022-12-09 07:23:11
【问题描述】:
我在多个项目中运行 Next js 和 Next Auth,突然间所有项目都决定因相同的错误而崩溃。
Module parse failed: Identifier '_react' has already been declared (14:6)
File was processed with these loaders:
* ./node_modules/next/dist/build/webpack/loaders/next-swc-loader.js
You may need an additional loader to handle the result of these loaders.
| const _material = require("@mui/material");
| const _xDataGrid = require("@mui/x-data-grid");
> const _react = require("next-auth/react");
| const _reportTable = /*#__PURE__*/
一个崩溃的简单例子看起来像这样......
正如您从下面的示例中看到的那样。我没有导入两次反应。
import React from "react";
import { Box } from "@mui/material";
import { DataGrid, GridColDef, GridRowsProp } from "@mui/x-data-grid";
import { getSession } from "next-auth/react";
import ReportTable from "../src/components/ReportTable";
export default function Home() {
const findSession = () => {
const session = getSession();
console.log(session);
return session;
};
return (
<Box>
<ReportTable title="Price Books">
<DataGrid
sx={{ border: "0" }}
rows={rows}
columns={columns}
headerHeight={40}
/>
</ReportTable>
</Box>
);
}
如果我删除顶部的 getSession 导入,一切运行正常。我团队中的其他开发人员可以很好地运行这些项目,所以我认为这是我这边的环境问题。
还有其他人遇到过这个问题吗?
我已经构建了该项目并且运行良好。错误只发生在我的开发环境中。 我还在我的个人机器上克隆了 repo,它在那里也运行良好。
【问题讨论】: