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 |1 Answer
Reset to default 0I solved the problem. i was searching related questions and this one solved my problem "next build" failing due to useContext error
useContext
? – OverSamu Commented Mar 2 at 9:38Ctrl+Shift+F
ofuseContext
returns no matches? – OverSamu Commented Mar 2 at 9:42