Netlify和Heroku不会部署我的Nextjs项目[duplicate]

41zrol4v  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(157)

此问题在此处已有答案

Cannot find module or type declarations while it works in local build(2个答案)
三个月前关门了。
我试图在heroku或netlify上部署我的应用程序,但在这两个上我都得到了这个不正确的导入路径错误。我很困惑为什么会发生这种情况,导入是正确的,并在本地工作。
日志

./pages/_app.tsx:7:27
6:31:19 PM: Type error: Cannot find module '../styles/Body' or its corresponding type declarations.
6:31:19 PM:    5 | import { Box } from "@mui/material";
6:31:19 PM:    6 | import { useState } from "react";
6:31:19 PM: >  7 | import pageContainer from "../styles/Body";
6:31:19 PM:      |                           ^
6:31:19 PM:    8 | 
6:31:19 PM:    9 | function MyApp({ Component, pageProps }: AppProps) {
6:31:19 PM:   10 |   const [darkMode, setDarkMode] = useState(false);
6:31:19 PM: > Build error occurred
6:31:19 PM: Error: Call retries were exceeded
6:31:19 PM:     at ChildProcessWorker.initialize (/opt/build/repo/node_modules/next/dist/compiled/jest-worker/index.js:1:11661)
6:31:19 PM:     at ChildProcessWorker._onExit (/opt/build/repo/node_modules/next/dist/compiled/jest-worker/index.js:1:12599)
6:31:19 PM:     at ChildProcess.emit (node:events:513:28)
6:31:19 PM:     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) {
6:31:19 PM:   type: 'WorkerError'
6:31:19 PM: }
6:31:19 PM: ​
6:31:19 PM: ────────────────────────────────────────────────────────────────
6:31:19 PM:   "build.command" failed                                        
6:31:19 PM: ────────────────────────────────────────────────────────────────
6:31:19 PM: ​
6:31:19 PM:   Error message
6:31:19 PM:   Command failed with exit code 1: CI= npm run build (https://ntl.fyi/exit-code-1)

_应用程序.tsx

import "../styles/globals.css";

import pageContainer from "../styles/Body";

function MyApp({ Component, pageProps }: AppProps) {
  const [darkMode, setDarkMode] = useState(false);

  return (
    <>
      <Box sx={pageContainer(darkMode)}>
          <NavBar darkMode={darkMode} onSetDarkMode={setDarkMode} />
          <Component darkMode={darkMode} {...pageProps} />
      </Box>
    </>
  );
}

export default MyApp;

样式/正文.tsx

const container = {
  direction: "rtl",
  padding: "1rem 0 1.6rem",
  backgroundColor: "#f5f5f5",
};

const nightMode = {
  backgroundColor: "#1E272E",
};

export default function pageContainer(isNight: boolean): object[] | object {
  return isNight ? [container, nightMode] : container;
}

修复:观众可能有这个问题。日志错误是正确的,在我的情况下,问题是我改变了文件名从'body.tsx'到'Body.tsx',然后提交它。我检查了我的github,文件名仍然是'body. tsx',我的导入是'Body.tsx',这是问题。希望这能解决你的问题

dfty9e19

dfty9e191#

大多数情况下,可能是路径不正确,请检查路径,但如果这不是问题所在,则将其重命名为PageContainer。

vqlkdk9b

vqlkdk9b2#

我不知道这是否有帮助,但你需要改变

import pageContainer from "../styles/Body";

import PageContainer from "../styles/Body";

希望能有所帮助

相关问题