Replies: 21 comments 35 replies
-
This is amazing, thank you! After having switched over an application of mine to the new This means that the "1 MB" threshold mentioned above has now been crossed:
|
Beta Was this translation helpful? Give feedback.
-
This is going to be a great addition to Next.js! I have a few questions though. Are you planning to run a real V8 or edge environment on development? This way errors are realistic if you try to use an unsupported API or any edge case that happens only in the production environment. Also, the |
Beta Was this translation helpful? Give feedback.
-
Have been digging into Next and really liking it so far in the context of evaluating it for our business needs and the Middleware API is great! However, the limitations they impose as per the Edge Runtime restrictions... not so much. 😅 So it was great to see this Discussion in my searching as this limiting factor seems to come up often as a frequent topic when doing some casual searching of recent posts
Presumably, with the option to specify the If not, is that something the team would consider and / or is there a way to turn "off" the Edge Runtime in the interim? Is that what something like next-connect is for? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Is this coming soon? |
Beta Was this translation helpful? Give feedback.
-
Any updates on this? 🥹 |
Beta Was this translation helpful? Give feedback.
-
Sorry for the slow response everyone -- yes, it's out as an experimental feature - docs can be seen here! |
Beta Was this translation helpful? Give feedback.
-
@jescalan It is not working. I tried: // next.config.js
module.exports = {
experimental: {
runtime: 'nodejs',
},
} Also tried, import { NextResponse } from 'next/server';
import { writeFile, readFile, appendFile } from 'fs/promises';
export async function middleware(req) {
appendFile(/* Do some stuff*/);
return NextResponse.next();
}
export const config = {
runtime: 'nodejs',
}
When printing the ENV variable, it is |
Beta Was this translation helpful? Give feedback.
-
As @martinjlowm mentioned here #34179 (reply in thread). The experimental flag does not apply to the runtime for middleware. Any feedback on that? |
Beta Was this translation helpful? Give feedback.
-
@Jelle-vz Hey!
), maybe it's not the perfect approach , but I was really surprised when I could use neither: |
Beta Was this translation helpful? Give feedback.
-
@shuding I've successfully tested the edge runtime to work with other V8-based (edge) providers like Cloudflare Pages / Workers, but I feel like the build output could be optimized to provide more flexibility and efficiency on where you deploy Next.js on the edge. In the current implementation of the build export of Next.js, each function is implemented as its own individual server with only the routes for that one specific page or API endpoint. On platforms like Cloudflare, they require you to bundle everything into one single Worker. This means for it to run properly there, you'd need to write your own, custom router. These individual functions also cause side-effects, currently in next.js/packages/next/server/web/adapter.ts Line 217 in 4cd8b23 In an experimental implementation of an edge function that bundles these, I essentially import all the edge functions into a single one based on Preferably, I'd love to see these pages exported more efficiently, maybe as truly individual pages with a separate file for the router/server, so that other tools and platforms can provide their own routers for it. The Vercel Build API has this issue too, but worse since the Vercel Build Output API doesn't do chunking. Would love to get your thoughts on supporting other platforms and what good methods forward would be. Here's an example implementation https://nextflare-demo.pages.dev/ (source code is available on request). |
Beta Was this translation helpful? Give feedback.
-
Does the edge runtime supports post requests? I checked the docs and could not find any information that they could not |
Beta Was this translation helpful? Give feedback.
-
Just wanted to share feedback on this as well, as along with quite a few others in this thread, may have been under a different impression of the outcome here?
As I understand it, prior to this change, here was the current status of support for Node / Edge
Now after this change, we have this
And so I think what might have caught myself and others by surprise is that Middleware + Node is still 🚫 ? Are we missing something? All of my testing has concluded that Middleware in NodeJS is not supported. 😢 So would it be possible to get Middleware in Node.js at some point? 💯
|
Beta Was this translation helpful? Give feedback.
-
Currently blocked even experimenting with Next 13 app directory until middleware can run as non-edge. What's especially frustrating is that this is self-hosted anyway. Our middleware is running in Node regardless! Please let us remove this limitation 🙏🙏🙏 |
Beta Was this translation helpful? Give feedback.
-
Hey! Thank you all for great job! I tried to use edge runtime on vercel with
but after upgrading to next
but it also does not work. Please help me to use edge runtime for the whole project |
Beta Was this translation helpful? Give feedback.
-
Is this RFC dead? No node runtime on middleware at all? |
Beta Was this translation helpful? Give feedback.
-
I need a way to set the edge runtime to the whole project. Pages can be configured from a root layout, but API routes must be configured individually. |
Beta Was this translation helpful? Give feedback.
-
I see this doc now I guess middleware can not be used with nodejs runtime. |
Beta Was this translation helpful? Give feedback.
-
Imagine building a framework for building web apps with server side rendering that does not support running simple functions on every http request on the server (to handle cross cutting concerns like logging, tracing, auth, cookies, headers). This restriction that middleware only runs in the edge runtime is awful. I spend a lot of time configuring middleware to work with my auth logic just to find out that I can not use it with my simple node.js custom deployment. I dont want to be forced to ANY hosting provider, I want to choose myself where I want to host the server that runs my app. This is the problem with a profit-oriented company really locking the community to a particular deployment platform. AT LEAST stating that middleware can only run in edge runtime which is only really supported by vercel should be the first thing in the middleware documentation, so everybody knows what they sign up for. Middleware running in node.js alongside the other server code should be the default and running on the edge should be the opt-in. Not the other way around! And the other way is not even supported... Man I had a bad gut feeling with next. How this got 100k stars? Delusional. For all folks struggling with this and don't have the biggest performance requirements: Spin up a reverse proxy that handles your middleware stuff and route it to your actual pure node.js next.js server. And for folks who are not yet locked in: Really think about using something different than next :) |
Beta Was this translation helpful? Give feedback.
-
Sad to see this wasn't in Next.js 15, makes me wonder if you guys are even considering implementing this... Will keep myself posted on the topic as It really means a problem for us at this point in time. |
Beta Was this translation helpful? Give feedback.
-
+1 I wanted to serve blog images in the directory along with blog articles other than public asset strategy. I created a middleware, but it runs on only edge runtime and doesn't support filesystem access. I need the middleware can run on nodejs runtime as well. |
Beta Was this translation helpful? Give feedback.
-
@leerob @feedthejim @shuding this discussion should probably be closed and locked, since there is a lot of outdated information and misinformation above. For anyone new coming to this discussion, this RFC is NOT about a Node.js runtime in Middleware. If you're looking for Node.js runtime support in Middleware, check out these discussions instead:
Node.js middleware support has since landed in Next.js canary versions:
Also - Turbopack support is coming: |
Beta Was this translation helpful? Give feedback.
-
Edit: See latest update here: #34179 (comment)
Beta Was this translation helpful? Give feedback.
All reactions