Getting 500 error instead of 404

Hi Developers,

I am using nextjs site with netlify. but I am getting 500 errors on a not found page.

this is the screenshot of netlify odb handler function. but everything is working fine on localhost and vercel. the problem is on the netlify only,

this is the netlify link:
and this is vercel link:

Hey there, @tfsomrat :wave:

Thanks for reaching out! Sorry to hear you are encountering obstacles. Can you please share your project repo that corresponds with this site? This will help us look into your set up a bit more closely.

Hello @hillary

I am sorry for the late reply, I was a little busy exploring Nextjs and Netlify. I cannot share the project repo because of company policy. but I have created another project which has the same issue.

here is the repo: Somrat / next-boilerplate · GitLab
and also the live demo:
getting 500 instead of 404:

:wave: @tfsomrat , this blog post walks through how to resolve the path to any additional files that should be included in the function deployment during build: How to Include Files in Netlify Serverless Functions

Let us know if that helps or we should keep digging! :slight_smile:

Hey @audrey

I have tried so many things and ways, Still, I couldn’t solve this issue. I recently made a nextjs template that has the same problems.

Github: GitHub - themefisher/bookworm-light-nextjs: Bookworm is a minimal NextJs Tailwind blog starter template.

The code is open source, you can download and check the code and netlify settings. any help would be appreciated. Thank you

Hey @tfsomrat,

Have you checked the function console: Netlify App?

I see this error:

Are you trying to use content folder in your app?

If yes, you might wish to refer to:

(already shared by @audrey above).

In your template, I can see you’re trying to access content/posts instead of content. So instead of content/*.md, you should probably include content/*.

Thanks for your reply @hrishikesh, I have updated the netlify.toml settings that you have suggested. but it still not working.

Hey @hillary @hrishikesh

Sorry for mentioning all of you guys. It’s been so long since I have been facing this issue. and I have created an open-source template with nextjs in that time. still, I couldn’t find any solutions from here or anywhere else. please give me a solution for this issue.

Sourcecode: GitHub - themefisher/bookworm-light-nextjs: Bookworm is a minimal NextJs Tailwind blog starter template.
Netlify: (getting 500 error on 404 page)
Vercel: (works perfectly)

I hope I’ll get a proper solution for this time. thank you.

Hi @tfsomrat,

I’ve opened a PR to fix this. However, when I tried visiting a random page like /jugbj for example, the page still fails. The error in this case is:

TypeError: Cannot destructure property 'frontmatter' of 'pageData[0]' as it is undefined.
  at getRegularPage (/var/task/.next/server/chunks/307.js:81:13)
  at getStaticProps (/var/task/.next/server/pages/[regular].js:721:99)
  at Object.renderToHTML (/var/task/node_modules/next/dist/server/render.js:451:26)
  at processTicksAndRejections (node:internal/process/task_queues:96:5)
  at async doRender (/var/task/node_modules/next/dist/server/base-server.js:915:38)
  at async cacheEntry.responseCache.get.isManualRevalidate.isManualRevalidate (/var/task/node_modules/next/dist/server/base-server.js:1020:28)
  at async /var/task/node_modules/next/dist/server/response-cache.js:69:36

The problem appears to be something with the code for this particular path. Maybe that’s expected, but I thought I should let you know.

Sorry for the previous message. your PR doesn’t resolve this issue. I have checked the vercel link and thought it has been fixed. but it’s not working. really sorry about the miss information. It’s still going to the 500 page

so there is no way to properly host nextjs templates with netlify!!

Hey @tfsomrat,

Since you’ve not provided any additional details, I’m assuming it’s the same error I have already reported in my last post. I think the stack trace was pretty clear to point out the cause of the issue.

In any case, I’ve raised another PR:

which fixes that issue. I’m not sure if you’re having any other problem, as you’ve not mentioned that.

It’s still not ideal as it renders a different 404 page than you’d expect:

You can ignore the images for now, this was just a test.

We’ll confirm with the devs why there’s a discrepancy in the local vs Netlify setup - but to your point, it’s indeed possible to host Next.js on Netlify.

1 Like

Hey @tfsomrat,

Our devs have confirmed this bug - and it turns out to be related to: [Bug]: Fallback false is ignored · Issue #1179 · netlify/next-runtime · GitHub. As soon as that is fixed, you would not have to use the workarounds that you’ve currently put in place.

1 Like