最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Error occurred prerendering page while next building - Stack Overflow

programmeradmin0浏览0评论

I’m in trouble while building with Next.js. I am using React 18, Next.js 14, and Node 18 versions. I've tried all other compatible versions with my code, but when I attempt to build my project with Next.js, I get an error on all pages. The error is:

TypeError: Cannot read properties of null (reading 'useContext')

Also, I should mention that when I use npx create-next-app and try to build the project without any code changes or additions, I get the same errors for all pages:

> Export encountered errors on following paths:
        /_error: /404
        /_error: /500
        /_not-found/page: /_not-found
        /

I don’t know why I’m getting this error in an auto-created project. What am I missing? I’ve tried all possible solutions, like deleting dependencies or reinstalling Node, Next.js, and React globally, but I still get the same error. I’m also using the app directory project structure with Next.js, and I’ve added a layout.tsx file here:

import type { Metadata } from "next";
import Navbar from '../app/components/Navbar';
import Footer from '../app/components/Footer';

import "./globals.css";

export const metadata: Metadata = {
  title: "title",
  description: "description ",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="tr">
      <body className="antialiased">
        <Navbar />
        <main className="pt-14">{children}</main>
        <Footer />
      </body>
    </html>
  );
}

I should reiterate that even when I create a Next.js project without adding any code, I still cannot get the build to work on any version. However, in development mode, my projects work perfectly and run smoothly in React Dev Tools or the console. For any helps thanks.

I’m in trouble while building with Next.js. I am using React 18, Next.js 14, and Node 18 versions. I've tried all other compatible versions with my code, but when I attempt to build my project with Next.js, I get an error on all pages. The error is:

TypeError: Cannot read properties of null (reading 'useContext')

Also, I should mention that when I use npx create-next-app and try to build the project without any code changes or additions, I get the same errors for all pages:

> Export encountered errors on following paths:
        /_error: /404
        /_error: /500
        /_not-found/page: /_not-found
        /

I don’t know why I’m getting this error in an auto-created project. What am I missing? I’ve tried all possible solutions, like deleting dependencies or reinstalling Node, Next.js, and React globally, but I still get the same error. I’m also using the app directory project structure with Next.js, and I’ve added a layout.tsx file here:

import type { Metadata } from "next";
import Navbar from '../app/components/Navbar';
import Footer from '../app/components/Footer';

import "./globals.css";

export const metadata: Metadata = {
  title: "title",
  description: "description ",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="tr">
      <body className="antialiased">
        <Navbar />
        <main className="pt-14">{children}</main>
        <Footer />
      </body>
    </html>
  );
}

I should reiterate that even when I create a Next.js project without adding any code, I still cannot get the build to work on any version. However, in development mode, my projects work perfectly and run smoothly in React Dev Tools or the console. For any helps thanks.

Share Improve this question asked Mar 2 at 9:33 samsasamsa 888 bronze badges 4
  • Where are you using useContext? – OverSamu Commented Mar 2 at 9:38
  • any where i worked on vs code and i tried to search in project but there is a no using useContext – samsa Commented Mar 2 at 9:41
  • So Ctrl+Shift+F of useContext returns no matches? – OverSamu Commented Mar 2 at 9:42
  • 1 Yes definitely no usage. I search with Ctrl+Shift+F and i see that it's not used anywhere. Also, even if I missed it when I wrote my own, when I run npx create-next and then go to the folder and try running next build for the first time, I still get the same error. Keep in mind that in the project created via terminal, there is no way to have useContext. – samsa Commented Mar 2 at 9:48
Add a comment  | 

1 Answer 1

Reset to default 0

I solved the problem. i was searching related questions and this one solved my problem "next build" failing due to useContext error

发布评论

评论列表(0)

  1. 暂无评论