Error deploying Next.js => Minified React error #31 during deployment – Next.js

So I seem to be getting a bunch of issues when deploying my Next.js blog application to vercel (and other platforms), or running “npm run build”. It all works fine in local development mode.

Here is how my app is structured => enter image description here

Here is a sample of the errors that I am getting when deploying and running “npm run build” =>

Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=%5Bobject%20Promise%5D for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:490)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Xc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:409)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:210)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
Error occurred prerendering page "/main". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Minified React error #31; visit https://reactjs.org/docs/error-decoder.html?invariant=31&args[]=%5Bobject%20Promise%5D for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:490)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Xc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:409)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:210)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at Zc (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
    at Z (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/vercel/path0/my-app/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
Error getting static props TypeError: Cannot read properties of undefined (reading '0')
    at /vercel/path0/my-app/.next/server/pages/main.js:3:43
    at Array.map (<anonymous>)
    at e (/vercel/path0/my-app/.next/server/pages/main.js:3:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async d (/vercel/path0/my-app/.next/server/pages/main.js:5:167)
TypeError: Cannot destructure property 'props' of '(intermediate value)' as it is undefined.
    at d (/vercel/path0/my-app/.next/server/pages/main.js:5:156)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
   Generating static pages (4/9) 
Error occurred prerendering page "/posts/null". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Error serializing `.post` returned from `getStaticProps` in "/posts/[slug]".
Reason: `undefined` cannot be serialized as JSON. Please use `null` or omit this value.
    at r (/vercel/path0/my-app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:446)
    at /vercel/path0/my-app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:683
    at Array.every (<anonymous>)
    at r (/vercel/path0/my-app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:580)
    at N (/vercel/path0/my-app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:1100)
    at e3 (/vercel/path0/my-app/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:26:294)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async exportPages (/vercel/path0/my-app/node_modules/next/dist/export/routes/pages.js:84:28)
    at async exportPageImpl (/vercel/path0/my-app/node_modules/next/dist/export/worker.js:205:16)
    at async Span.traceAsyncFn (/vercel/path0/my-app/node_modules/next/dist/trace/trace.js:154:20)
   Generating static pages (6/9) 
Error getting static props TypeError: Cannot read properties of undefined (reading '0')
    at /vercel/path0/my-app/.next/server/app/page.js:25:43
    at Array.map (<anonymous>)
    at e (/vercel/path0/my-app/.next/server/app/page.js:25:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ns (/vercel/path0/my-app/.next/server/app/page.js:27:167)
Error getting static props TypeError: Cannot read properties of undefined (reading '0')
    at /vercel/path0/my-app/.next/server/app/page.js:25:43
    at Array.map (<anonymous>)
    at e (/vercel/path0/my-app/.next/server/app/page.js:25:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ns (/vercel/path0/my-app/.next/server/app/page.js:27:167)
TypeError: Cannot destructure property 'props' of '(intermediate value)' as it is undefined.
    at ns (/vercel/path0/my-app/.next/server/app/page.js:27:156)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: '3711528405'
}
TypeError: Cannot destructure property 'props' of '(intermediate value)' as it is undefined.
    at ns (/vercel/path0/my-app/.next/server/app/page.js:27:156)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: '3711528405'
}
TypeError: Cannot destructure property 'props' of '(intermediate value)' as it is undefined.
    at ns (/vercel/path0/my-app/.next/server/app/page.js:27:156)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: '3711528405'
}
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot destructure property 'props' of '(intermediate value)' as it is undefined.
    at ns (/vercel/path0/my-app/.next/server/app/page.js:27:156)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Error: Command "npm run build" exited with 1

The problem is that I really don’t have any idea where in the application these errors happen. Any help narrowing it down would be appreciated.

Main.tsx, which acts as my “homepage” =>

import { Separator } from "@/components/ui/separator";
import Post from "../components/post";
import sanityClient from "@/lib/sanityclient";
import groq from "groq";

interface Post {
  id: string;
  title: string;
  content: string;
}

interface PostProps {
  posts: Post[];
}

const Main = async () => {

  // fetching posts to display on homepage
  async function getPosts() {
    try {
      const posts = await sanityClient.fetch(groq`
        *[_type == "post"]
      `);
  
      // Fetching categories
      const postsWithCategories = posts.map(async (post: { categories: { _ref: any; }[]; }) => {
        const categoryId = post.categories[0]._ref;
        const categoryData = await sanityClient.fetch(groq`
          *[_type == "category" && _id == "${categoryId}"]
        `);
  
        return {
          ...post,
          category: categoryData[0] || null,
        };
      });
      
      const resolvedPosts = await Promise.all(postsWithCategories);
      return { props: { posts: resolvedPosts } };
    } catch (error) {
      console.error("Error getting static props", error);
    }
  }

  const { props: { posts } } = (await getPosts()) as { props: { posts: any[]; } }; // Type assertion
  
  return (
    <div id="main-container">
      <div id="main-text" className="flex flex-col items-center">
        <h1 className="font-bold">VoiceOvery Blog</h1>
        <p className="text-xl">Gain more insight into the world of AI generated voices and other ai innovations.</p>
      </div>
      <div className="pt-2 mb-5">
        <Separator />
      </div>
      <Post posts={posts} />
    </div>
  )
};



export default Main;

Post.tsx, which is the article or “post” that I am displaying =>

import { Card, CardContent } from "@/components/ui/card";
import { testData } from "@/lib/testdata";
import Image from "next/image";
import Link from "next/link";
import imageUrlBuilder from "@sanity/image-url";
import sanityClient from "@/lib/sanityclient";

interface BlogPost {
  body: any;
  category: {
    title: string;
  };
  _id: string;
  slug: {
    current: string;
  };
  title: string;
  content: string;
  _createdAt: number;
  publishedAt: string,
  mainImage: {
    _type: string;
    asset: {
      _ref: string;
    };
  };
}

interface PostProps {
  posts: BlogPost[];
}

const Post = ({ posts }: PostProps) => {
  // Check if post is empty
  if (!posts) {
    return <p>No data</p>;
  };

  // Making sure the image works
  const builder = imageUrlBuilder(sanityClient)

  const urlFor = (imageUrl: string) => {
    return builder.image(imageUrl)
  };

  // Trimming date
  const trimmedDate = (dateString: string) => dateString.split("T")[0];


  return (
    <div id="article" className="flex flex-col space-y-20 sm:grid grid-cols-3 gap-4 gap-y-[70px] pt-6 md:space-y-0">
      {posts !== null && posts !== undefined && posts.length > 0 && 
      posts.map(article => (
        <Link
          href={`/posts/${article.slug.current}`}
          id="article-container"
          className="flex items-center justify-center pt-2 cursor-pointer" 
          key={article._id} 
          >
          <div className="w-[370px] h-[310px] items-center flex">
            <div className="space-y-1">
              <Image 
                className="rounded-md"
                src={urlFor(article.mainImage.asset._ref).url()}
                alt="article-picture"
                width={370}
                height={310}
              />
              <div id="article-text">
                <p id="category" className="text-muted-foreground pb-2 text-lg">{article.category.title}</p>
                <h1 className="text-3xl font-semibold">{article.title}</h1>
                <p className="text-xl">{article.body[0].children[0].text}</p>
                <div id="author-date" className="flex space-x-2">
                  <p>Alex -</p>
                  <p className="text-muted-foreground">{trimmedDate(article.publishedAt)}</p>
                </div>
              </div>
            </div>
          </div>
        </Link>
      ))}
    </div>
  )
};

export default Post;

[slug].tsx, which fetches the article from sanity.io =>

import sanityClient from "../../lib/sanityclient";
import Image from "next/image";
import { useRouter } from "next/router";
import groq from "groq";
import { Inter } from "next/font/google";
import imageUrlBuilder from "@sanity/image-url";
import Article from "@/components/article";
import Layout from "../layout";

export async function getStaticPaths() {
  const query = groq`*[_type == "post"].slug.current`;
  const slugs = await sanityClient.fetch(query);
  const paths = slugs.map((slugData: any) => ({
    params: { slug: String(slugData) }
  }));
  return {
    paths,
    fallback: 'blocking' // or false or 'static'
  };
}

export async function getStaticProps(context: { params: { slug: any; }; }) {
  const slug = context.params.slug;
  const query = groq`*[_type == "post" && slug.current == "${slug}"]`;
  const post = await sanityClient.fetch(query);

  if (!post) {
    return { notFound: true };
  }

  return { props: { post: post[0] } };
}

const inter = Inter({ subsets: ["latin"] });

const Post = ({ post }: any) => {
  // ... other logic

  return (
    <Layout>
      <Article post={post} />
    </Layout>
  );
}

export default Post;

article.tsx, contains the article / blog post itself =>

import imageUrlBuilder from "@sanity/image-url";
import Image from "next/image";
import sanityClient from "@/lib/sanityclient";
import { PortableText } from "@portabletext/react";
import { Button } from "./ui/button";

const Article = ({ post }: any) => {
  // Making sure the image works
  const builder = imageUrlBuilder(sanityClient)

  const urlFor = (imageUrl: string) => {
    return builder.image(imageUrl)
  };

  let imageUrl = urlFor(post.mainImage.asset._ref).url();

  // Trimming date
  const dateString = post.publishedAt;
  const trimmedDate = dateString.split("T")[0];
  
  const articleText = post.body;

  return (
    <div>
      <div id="article" className="w-screen flex items-center justify-center">
        <div id="image-title" className="flex flex-col">
          <p>Published at {trimmedDate}</p>
          <h1 className="font-semibold">{post.title}</h1>
          <div id="author-name" className="flex flex-row items-center space-x-1 mb-5">
            <p className="text-muted-foreground text-xl">By</p>
            <p className="text-xl">Alex</p>
          </div>
          <Image 
            src={imageUrl}
            alt="article-image"
            className="rounded-md"
            width={690}
            height={310}
          />
        </div>
      </div>
      <div className="flex flex-col items-center pt-12">
        <div id="article-text" className="w-[690px]">
          <PortableText 
            value={articleText}
          />
        </div>
      </div>
    </div>
  )
}

export default Article

package.json =>

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@portabletext/react": "^3.0.18",
    "@radix-ui/react-separator": "^1.0.3",
    "@radix-ui/react-slot": "^1.0.2",
    "@sanity/client": "^6.17.2",
    "@sanity/image-url": "^1.0.2",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.1",
    "groq": "^3.40.0",
    "lucide-react": "^0.377.0",
    "next": "14.2.3",
    "next-themes": "^0.3.0",
    "react": "^18",
    "react-dom": "^18",
    "sharp": "^0.33.3",
    "tailwind-merge": "^2.3.0",
    "tailwindcss-animate": "^1.0.7"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.3",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

next.config.mjs =>

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: false,
  images: {
    domains: ['cdn.sanity.io'],
  },
};

export default nextConfig;

Any idea’s on how I can solve this error? No idea how to begin solving this. Any pointers would be very helpful.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật