-
Notifications
You must be signed in to change notification settings - Fork 26.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js default not-found/404 page doesn't render on Vercel deployments #60477
Comments
@ericpesto I have thoroughly investigated the reported issue, and it appears to be related to deployment on Vercel rather than a 404 error. Upon closer inspection, I noticed that some files crucial for your project are missing, specifically those that you are attempting to import. It seems that when you pushed the repository to GitHub, an empty folder structure may have been created. GitHub typically does not support an empty folder structure unless it contains at least one file. Consequently, when deploying this project on Vercel, an error arises due to the absence of necessary files. To address this issue, I recommend ensuring that the repository on GitHub includes the required files within the folder structure before attempting the deployment on Vercel. This should resolve the error encountered during the deployment process. If you have any further questions or need assistance with this matter, please feel free to reach out. |
My project is closed source and as such I can't provide the offending code/repo, building a like for like project in code sandbox to replicate the issue would take a fair bit of time. On our end we have no problem deploying on Vercel, we can see the site live with no errors. The issue is that our 404 pages don't render for the site hosted on Vercel when incorrect urls paths are specified, whereas they do when running the project locally |
Project Settings / Change Framework preset from Other to Next.js |
Our framework preset already is set to Next.js on the Vercel Dashboard |
Add a custom 404 page this should fix the problem |
We did try this, see above:
|
I had a similar issue with App router only code. My workaround was to force 404 page based on the pathname: // middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
// the following code is taken from: https://nextjs.org/docs/app/building-your-application/routing/middleware#setting-headers
export function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-pathname", request.nextUrl.pathname);
return NextResponse.next({
request: { headers: requestHeaders },
});
}
// the following code has been copied from https://nextjs.org/docs/app/building-your-application/routing/middleware#matching-paths
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
}
// app/page.tsx
import { headers } from 'next/headers';
import { notFound } from "next/navigation";
export default async function Page() {
const pathname = headers().get("x-pathname");
if (pathname !== "/") return notFound();
return <>{/*... your page code */}</>
} |
Any fix to this solution, having the same issue. I have not-found.tsx file in the app directory, works when run locally, but it never gets rendered in production for incorrect url? |
Redeploying doesn't make the problem gone. But in development server, the 404 page is doing its work. |
this worked for me inside app create a file at [...not_found]/page.tsx
Reason: Since dynamic routes are resolved after static routes, we can solve it by creating a dynamic catch-all route using a [...not_found] folder and add it to our app folder. |
This is still an issue for me as well.
I have only one dynamic route under app/[slug]. Adding aforementioned [...not-found] didn't help. Any other suggestions? |
I have the same issue. A dynamic route that is using I have one dynamic route in |
Good day, Hope that helps! :) |
It is not solving the problem. |
My file structure:
I have a
This does not matter. If someone is getting 500 error here it probably something else. Maybe |
I have the same structure, and it works fine for me, every route, even something/something/something-else is getting tracked by You can check my [post] page.js here and compare it to yours: https://github.com/eagrigorev/eagrigorev-website/blob/master/src/app/%5Bslug%5D/page.js Hope that will help :) |
Inside
export default async function ProfilePage({ params }: ProfilePageProps) {
const userId = validateId(params.id)
const token = await getServerToken()
if (!token) redirect('/')
const { profile } = await getUser(token, { userId })
return (
<ProfileCard {...profile}>
<Playback />
</ProfileCard>
)
}
export default function ProfileError({ error, reset }: ErrorProps) {
if (error.message === 'The access token expired') reset()
if (
error instanceof Error &&
[VALIDATION_FAILED_UUID_EXPECTED, USER_NOT_FOUND].includes(error.message)
)
return notFound()
console.error(error)
} Everything works on development, the issue occurs on production. Not found page is not rendered, instead I'm getting console errors.
|
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/dry-dust-r83nds?file=%2Fnext.config.js%3A10%2C32
To Reproduce
Current vs. Expected behavior
When navigating to incorrect/non-existent paths, the Next.js default not-found/404 page doesn't render on Vercel deployments, but does during local development.
We would expect to see the 404/not-found page in the Vercel's production deployment, just as we see it in dev.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:32:11 PDT 2023; root:xnu-10002.41.9~7/RELEASE_ARM64_T6030 Binaries: Node: 21.3.0 npm: 10.2.4 Yarn: N/A pnpm: N/A Relevant Packages: next: 14.0.5-canary.46 eslint-config-next: 14.0.3 react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Not sure, App Router, Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
We are hosting our Next.js app on Vercel.
As per these Next.js docs we have also tried making our own not-found.tsx component and placed it under ./app so all incorrect paths should result in the custom 404 being displayed, but they don't on Vercel, but do during local development. As suggested in other threads, we have also tried placing it throughout the application, but with no with success.
Note: running in production mode locally still gives a 404
The text was updated successfully, but these errors were encountered: