NextJS Dynamic Routes resulting in 500 error but working perfect on Vercel

Site: FlockX Community Portal (Link: FlockX Community Portal)

Issue: Dynamic Routes in NextJS (v14.0.4) Yield 500 Error on Netlify Deployment

Details: In my NextJS application, all dynamic routes are encountering a 500 error post-deployment on Netlify. This issue doesn’t arise during local development or when deploying via Vercel.

  • Local Development:
    • npm run dev: Functions correctly on localhost.
    • netlify dev: No issues on localhost.
    • npm run build followed by npm run start: Simulates build process successfully on local environment.
  • Vercel Deployment: Fully operational with no errors.

Attempts to Resolve:

  • Examined and implemented solutions from other Netlify support queries, but to no avail.

Request: Any guidance or suggestions to fix this issue would be highly appreciated.
Support

cc @hrishikesh @Melvin

Next.js 14 doesn’t work well on Netlify at the moment and this would be resolved in v5 of the Next.js Runtime scheduled to release in this quarter (currently in beta).

Thanks for the update @hrishikesh . I attempted to revert my code to a point where dynamic routing was functioning correctly. This rollback occurred before the introduction of the Node module package known as “@elastic/elasticsearch.” I would like to request verification regarding whether certain packages may have caused the disruption in dynamic routing.

@hrishikesh Just wanted to touch base on this discussion

Interesting. The current error that you’re seeing on: staging.community.flockx.io, has nothing to do with Next.js compatibility. It’s a system-level issue. We are seeing the error:

Lambda was not able to unzip the file

Could you potentially try to re-deploy the site to see if it works?

I tried to redeploy it multiple times, but still getting same issue. Can you please share more info @hrishikesh . Is it particular package issue or nextjs issue or netlify issue?

@hrishikesh I just retriggered the build, I am still getting the same error: https://deploy-preview-40.community.flockx.io/activity/776d6c55-509c-4b73-bfc3-974d0f86ac5d

Sorry to hear about this. I have escalated it to the devs and would let you know once they revert.

Could you please check if you have the follwing in your .npmrc:

public-hoist-pattern[]=*
node-linker=hoisted

Yes, I have following line in .npmrc

public-hoist-pattern[]=*.

Should I put node-linker=hoisted as well?

Yes, could you try adding that please?

@hrishikesh , it worked, thanks a lot. you are genius.

Can you please share what was the issue so that we can avoid such issues in future

This is related to PNPM: .npmrc | pnpm. The official doc is even mentioning that this is needed for serverless:

Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don’t support symlinks. An alternative solution for this problem is to bundle your application before deployment.

thanks @hrishikesh. I very much appreciate your help.