Next.js 14 Upgrade Results in 500 Status Code

Hello!

I’m currently experimenting with an upgrade to Next.js 14. The build runs fine (link) but trying to view the deploy preview results in an “Internal Server Error” to be displayed.

The deploy preview # is 1168 and the sitename is vertex-trade-testnet

This is the log from the netlify functions handler:

Nov 2, 07:47:59 AM: fddd2b5f ERROR   ⨯ Error: Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/amp-context'
Require stack:

- /var/task/node_modules/next/dist/shared/lib/head.js
- /var/task/node_modules/next/head.js
- /var/task/apps/trade/.next/server/pages/_app.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/apps/trade/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
- /var/task/___netlify-handler.js
- /var/runtime/index.mjs
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at /var/task/node_modules/next/dist/server/require-hook.js:54:36
at Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at mod.require (/var/task/node_modules/next/dist/server/require-hook.js:62:32)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/var/task/node_modules/next/dist/shared/lib/head.js:29:34)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/task/node_modules/next/dist/shared/lib/head.js',
'/var/task/node_modules/next/head.js',
'/var/task/apps/trade/.next/server/pages/_app.js',
'/var/task/node_modules/next/dist/server/require.js',
'/var/task/node_modules/next/dist/server/next-server.js',
'/var/task/apps/trade/.netlify/functions-internal/___netlify-handler/___netlify-handler.js',
'/var/task/___netlify-handler.js',
'/var/runtime/index.mjs'
]
}
Nov 2, 07:48:00 AM: fddd2b5f INFO [GET] / (SSR)
Nov 2, 07:48:00 AM: fddd2b5f Duration: 493.77 ms	Memory Usage: 214 MB
Nov 2, 07:48:37 AM: 694c6c76 ERROR ⨯ Error: Cannot find module 'next/dist/server/future/route-modules/pages/vendored/contexts/amp-context'
Require stack:
- /var/task/node_modules/next/dist/shared/lib/head.js
- /var/task/node_modules/next/head.js
- /var/task/apps/trade/.next/server/pages/_app.js
- /var/task/node_modules/next/dist/server/require.js
- /var/task/node_modules/next/dist/server/next-server.js
- /var/task/apps/trade/.netlify/functions-internal/___netlify-handler/___netlify-handler.js
- /var/task/___netlify-handler.js
- /var/runtime/index.mjs
at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
at /var/task/node_modules/next/dist/server/require-hook.js:54:36
at Module._load (node:internal/modules/cjs/loader:922:27)
at Module.require (node:internal/modules/cjs/loader:1143:19)
at mod.require (/var/task/node_modules/next/dist/server/require-hook.js:62:32)
at require (node:internal/modules/cjs/helpers:119:18)
at Object.<anonymous> (/var/task/node_modules/next/dist/shared/lib/head.js:29:34)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/task/node_modules/next/dist/shared/lib/head.js',
'/var/task/node_modules/next/head.js',
'/var/task/apps/trade/.next/server/pages/_app.js',
'/var/task/node_modules/next/dist/server/require.js',
'/var/task/node_modules/next/dist/server/next-server.js',
'/var/task/apps/trade/.netlify/functions-internal/___netlify-handler/___netlify-handler.js',
'/var/task/___netlify-handler.js',
'/var/runtime/index.mjs'
]
}
Nov 2, 07:48:37 AM: 694c6c76 INFO [GET] / (SSR)
Nov 2, 07:48:37 AM: 694c6c76 Duration: 609.21 ms	Memory Usage: 214 MB
3 Likes

With Next 13 already having issues, Next 14 will meet the same fate on Netlify. It will eventually be fixed, but right now there’s nothing to solve these errors.

Hey @hrishikesh, that doesn’t really feel like a satisfactory answer. We’re paying for Enterprise support and also facing this problem, so what’s the path to resolution? Moreover, what’s the core problem here that makes Next.js so difficult?

Next.js’ docs imply that you can self-host if on any Node server - which Netlify provides - so are they wrong? Not giving a full picture? I could definitely believe that they’re not putting in the effort to make it truly platform agnostic, so if that’s the case then we as users of Next.js should try to raise a red flag and apply some pressure from within their community.

2 Likes

Hey @kmcguire,

I’m sorry, but that’s as good an answer I can provide at the moment, especially on a public forum. The team is simply not checking any issues individually right now, till we roll out better support for the framework. For us, the question was:

  • should we spend time on invidual issues and keep on adding weird workarounds, only for Next.js to break it in another release?
  • OR should we ignore the current issues for some time, work on a robust support for the framework which would be hard to break, and then tackle the remaining issues (which might not be many)?

I think you can guess what choice we went with.

That’s true, but several features won’t work unless the underlying platform supports it. For example, ISR won’t work unless your server knows and understands that the cache needs to be cleared according to the response headers and then regenerate a page in the background, etc. The way Next.js hosting on Node.js server works in by leaving a server on forever with the next start command handling the requests.

Assuming the server supports all the primitives used by Next.js, it would work on a Node.js server, but it doesn’t work in a serverless environment. Netlify doesn’t provide a Node.js server, we provide a serverless environment. There have been other projects similar to ours: Index - OpenNext (open-next.js.org). This is the primary problem.

With each release, especially in Next.js 13, I personally saw a wave of breaking changes in the framework. These were not breaking changes for the end-user, but for a server like us. Based on a few dicussion with our devs, Next.js uses some very “different” ways of doing some things, which makes it hard for us, as we simply can’t do the exact same thing in our environment. We’re attempting to change things for the better, and that would take some time - considering the relevant team is significantally understaffed (about 3 devs).

While browsing through Reddit, I come across some threads where people criticise Vercel for “making it difficult to self-host Next.js”. Some people speak in favor of Vercel, others call them out. I don’t have a personal say on this as I have never tried to self-host it, but I was just trying to tell that there’s some level of dissatisfaction in the community regarding the way Vercel goes about Next.js. Is that enough to make them change things for the good? I don’t know.

1 Like

@hrishikesh I’m really not sure if “we’re making changes for the better but we are understaffed” is a great explanation. I understand that there are limitations to what is achievable vs. timeline, but it would at least be good to have some sort of roadmap to understand how Netlify is working to support the latest Next.js versions.

2 Likes

I’ve already shared what I can share right now (and probably more than what I should have). If waiting for a few weeks is not an option for your project, I’m sorry but I don’t have a better news today. You can make a decision to host your application elsewhere where you might get a better Next.js support, but that’s not going to happen on Netlify today, or at least not for the next few weeks.

Netlify may want to consider taking this page down then. It claims Netlify is “The better runtime for Next.js”, has “Unrivaled support for Next.js with zero configuration”, and “automatically installs everything you need to run your Next.js project”.

One of Netlify’s featured Next.js starters uses Next.js 14. If Netlify’s support for it isn’t working yet, the wording in your marketing should set better expectations.

I don’t see how a user signing up today would know that Next.js 14 (and 13 as you mentioned) has issues on Netlify.

2 Likes

The following post expresses a lot of my personal opinions and should not be interpreted as me trying to defend the company just because I work here.

While I understand your criticism and possible frustration, I’d also like to add some points here. I’m not a marketing expert, but based on my limited understanding, marketing is meant to sell products - not highlight the issues. The role of the marketing is to display a product, in a way that it sells. That’s not to say the product doesn’t have its limitations, but it’s also not marketing’s responsibility to portray it (unless it’s serious enough like tobacco warnings for example). Considering we’re not charing anyone for trying out Netlify to host Next.js, anyone is free to try and decide if Netlify is good enough for their needs or not. For our Enterprise users, we’re comitted to fix the issues, but this is not going to happen overnight. We’re also providing them timely support, workarounds and overall communication about whatever problems they’re having till we get all these issues fixed for good. We’re also publicly aknowledging the limitations and not trying to hide or censor the posts. Personally, I feel that accounts for something.

I can pass on your feedback about the page, but it’s unlikely it would be changed.

Regarding the starter, well the starter works - without issues. I haven’t said Next.js 14 won’t work at all, it could work, but you might have some issues. Looks like the starter code is not something that has any issues. Moreoever, you could probably check that the starter is clearly not maintained. It was never even updated to Next 13 by us - the only updates it got was from bots and a logo update from our end. The Next.js 14 update came from community. Since it appeared to work, it was merged.

We can go on in this post, but that’s not going to solve the problem, or help anyone in any meaningful way. There’s nothing in my control that I can do to immediately fix anything about this. I’d recommend not discussing this further as I don’t see anything fruitful coming out of this thread. As mentioned before, if waiting a few weeks is not an option for you, you’re free to make a decision about your project and host it elsewhere. If you need help migrating, we’re ready to assist with that too.

1 Like

Hey @hrishikesh, thank you for these responses. While our issue isn’t resolved (yet), I do appreciate the extra effort you’ve put in to make this topic a bit more transparent.

Will be keeping an eye out for the upcoming improvements to running Next.js on Netlify :eyes:

Marketing should not be misleading, which I believe this is. Next.js is not fully compatible with Netlify, which is fine, except that Netlify makes out of though it’s fully compatible (calls it’s support ‘better’, ‘unrivalled’, ‘everything you need’). At no point does it say some features are missing, or to check the docs for anything not supported. I’m aware that users on a free plan can go ahead and test things, it doesn’t change the fact the page is misleading.

In my country we have consumer protection laws where, if Netlify operated here, would require Netlify to refund customers based on this marketing page vs what’s delivered. I trust Netlify will fix the issues and I know they are difficult, but please Netlify, don’t promise what you cannot deliver right now.

We’re also publicly aknowledging the limitations and not trying to hide or censor the posts

This is true, the marketing page should be truthful too.

1 Like

Any updates on this. We’ve recently moved to next 14 and it’s causing a ton of errors for us. This has been outstanding since November. While you may think re-architecting the entire next.js hosting is a priority, over the individual issues… if issues that show 500 Internal Server Error to our customers are not resolved, My stakeholders are eventually going to to force me to move the hosting. I’m sure other developers are in the same position.

1 Like

There’s a private beta coming up next week, so things are starting to change. We’re still several weeks away from any public releases, but there’s progress happening. We’ve already seen a lot of issues resolved in our internal testing and would be working closely with the beta participants to iron out any more issues that arise.

3 Likes

@hrishikesh happy to volunteer for beta testing if you need more data/feedback!

Thank you, we will consider extending the current private beta list and update here if/when we do that.

Well only spend few weeks updating my project to find out that nextjs 14 is not working on Netlify. Not sure what to say, a complete waste of my time. Don’t advertise you support Next, when you don’t. What is the will the fix be ready???

1 Like

I don’t have anything to add than what’s already shared above, @nolafs.

Hey guys, i have a solution for Next js 14 + that seemed to work for me, amp-context is imported dynamically, which means it won’t be properly included in the Netlify function. We can force include it like this, i had problem with router-context and head-manager-context so i included those aswell:

netlify.toml:

[functions]
included_files = [
  "node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
  "node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
  "node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
]
1 Like

I think the problem is a bit broader and more related to next14 rather than amp-context

I tried it already but I am using a NX monorepro and I am having issues including files. If anyone knows how to include files correctly with NX, very much appreciated.