为什么Vercel无法构建我的Next.js tsx应用程序



当我在本地机器上运行npm run build和npm start时,它会完美地部署到localhost,但当我试图将相同的代码部署到Vercel时,我会收到以下错误:

08:28:16    Failed to compile.
08:28:16    ./pages/index.tsx:5:20
08:28:16    Type error: Cannot find module '../components/layout' or its corresponding type declarations.

这似乎是Layout组件的一个问题,我切换了重要组件的顺序,在尝试加载Layout组件时总是失败。这是组件的代码:

import Alert from "./alert";
import Footer from "./footer";
import Meta from "./meta";
type Props = {
preview?: boolean;
children: React.ReactNode;
};
const Layout = ({ preview, children }: Props) => {
return (
<>
<Meta />
<div className="min-h-screen">
<Alert preview={preview} />
<main>{children}</main>
</div>
<Footer />
</>
);
};
export default Layout;

index.tsx第5行看起来像这个import Layout from "../components/layout";,我已经确认这是Layout组件的正确路径。

你确定文件名是layout.tsx而不是layout.tsx:-(吗

我也经历了同样的事情。将layout.tsx固定为layout.tsx文件名和组件名必须相同。

最新更新