Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I keep getting an error when trying to run npm run build on my next.js project

Whenever I try to run npm run build for my project I get the error: Cannot read properties of undefined (reading ’email’). I understand it means that the email cannot be undefined, but I am unsure where it means, the code for the page it is reffering to is pasted below:

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 || "harmse688@gmail.com"}
        secret={props.user.uid}
        style={{ height: "100%" }}
      />
    </div>
  );
}

I have tried searching online for a fix, but have not found any fix yet, any help would be appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think it’s saying that the user is undefined. You could put props.user?.email to check if the user exists before it tries to key into the user object. You should also do it for the id props.user?.uid.

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

There may be a problem with how your passing in the user prop, it doesn’t seem to be receiving it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading