尝试在我的 next.js 项目上运行 npm run build 时不断收到错误

问题描述 投票:0回答:1

每当我尝试为我的项目运行 npm run build 时,都会收到错误:无法读取未定义的属性(读取“电子邮件”)。我理解这意味着电子邮件不能未定义,但我不确定这意味着什么,它所引用的页面的代码粘贴在下面:

import { auth } from "@/firebase";
import { signOut, User } from "firebase/auth";
import { PrettyChatWindow } from "react-chat-engine-pretty";

interface ChatProps {
  user: User;
}

export default function Page(props: ChatProps) {
  return (
    <div style={{ height: "100vh" }}>
      <button
        style={{ position: "absolute", top: "0px", left: "0px" }}
        onClick={() => signOut(auth)}
      >
        Sign Out
      </button>
      <PrettyChatWindow
        projectId="This is the ID I use for chatengine"
        username={props.user.email || "[email protected]"}
        secret={props.user.uid}
        style={{ height: "100%" }}
      />
    </div>
  );
}

我已尝试在线搜索修复程序,但尚未找到任何修复程序,任何帮助将不胜感激。

node.js npm
1个回答
0
投票

我认为这是说用户未定义。您可以放置 props.user?.email 在尝试键入用户对象之前检查用户是否存在。您还应该对 id props.user?.uid 执行此操作。

<PrettyChatWindow
  projectId="This is the ID I use for chatengine"
  username={props.user?.email || "[email protected]"}
  secret={props.user?.uid}
  style={{ height: "100%" }}
/>

如果您传递用户属性的方式可能存在问题,则它似乎没有收到它。

© www.soinside.com 2019 - 2024. All rights reserved.