Skip to content

Getting an weird error in production which is not happening in localhost #68072

Answered by riturajcodes
DB-db-dron asked this question in Help
Discussion options

You must be logged in to vote

The problem you are facing is due to static rendering of not-found.js.

Next.js thinks your page doesn't need to fetch or upload data if you don't use a dynamic function. This means it shows the same page to everyone, and any outgoing request can't be run because the page is delivered as static HTML from a CDN or edge server.

So, to solve this issue:

// app/not-found.js
import {headers} from "next/headers";

export default async function NotFound() {
    // sweet trick make the page into dynamic rendering
    const headersList = headers()
    return (
        <Custom404 />
    )
}

Put your logic of the 404 page inside a Custom404 component.
Mark the Custom404 page as "use client".

Hope it …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@DB-db-dron
Comment options

@DB-db-dron
Comment options

Answer selected by DB-db-dron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants