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.
image

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: https://tf-next-test.netlify.app/
and this is vercel link: https://tf-next-test.vercel.app/

1 Like

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: https://gitlab.com/tfsomrat/next-boilerplate
and also the live demo: https://tf-next-boilerplate.netlify.app/
getting 500 instead of 404: https://tf-next-boilerplate.netlify.app/test

: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 CSS blog starter template.
Netlify: https://bookworm-light-nextjs.netlify.app/

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 CSS blog starter template.
Netlify: https://bookworm-light-nextjs.netlify.app/ (getting 500 error on 404 page)
Vercel: https://bookworm-light-nextjs.vercel.app/ (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:

https://hk-next.netlify.app/565

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