-
Verify canary release
Provide environment informationI need to create a custom middleware for authentication and log some information. If I move the export async function middleware(req) {
try {
logger.log(req)
} catch(e) {
console.error(e)
} finally {
req.next()
}
}
export const config = {
runtime: 'nodejs',
}; I get errors because native APIs are not supported, but I need to use filesystem APIs. I tried configuring this into the conf within Is there any way to get rid of the edge runtime? In my humble opinion is causing more harm than usefulness. What browser are you using? (if relevant)No response How are you deploying your application? (if relevant)mext start Describe the BugI need to avoid edge function usage on middleware. Expected BehaviorIf properly configured, the edge function should not be used. Link to reproductionNot applicable To ReproduceNot applicable |
Beta Was this translation helpful? Give feedback.
Replies: 31 comments 13 replies
-
Also having issues with edge runtime. Tried adding config to the middleware. Tried modifying next.config.. (Where I had to upgrade to react@18) |
Beta Was this translation helpful? Give feedback.
-
I can't disable too. |
Beta Was this translation helpful? Give feedback.
-
You can use https://nextjs.org/docs/messages/edge-dynamic-code-evaluation |
Beta Was this translation helpful? Give feedback.
-
Yes -- there needs to be a way to disable edge runtime project-wide. Some of us have little need for edge, and it adds further complexity to simple implementations. I've been dealing with edge-related issues (via middleware, prisma, and now intermittent bugs that resolve on refresh) since I've started my next 13.4+ project. It is absolutely unacceptable -- there needs to be a global configuration to disable edge, or it ends up creeping into places that you don't expect it, causing extra development time and ultimately eroding my patience. |
Beta Was this translation helpful? Give feedback.
-
FWIW OP -- you can write an api endpoint and have your middleware call that to workaround edge's issues/limitations and have full node access within the api endpoint. |
Beta Was this translation helpful? Give feedback.
-
This prevents using database libraries like Prisma inside of middleware (prisma/prisma#21310) - I can understand why you wouldn't want that when deploying to the edge, but it's a frustrating restriction when I'm self-hosting my application (my use case being checking user auth in middleware). I've managed to work around this by putting all my authenticated routes in a route group and doing the auth check in its |
Beta Was this translation helpful? Give feedback.
-
+1 same issue, edge is not viable and just another weird vendor lock feature. Allow us to turn that off for our self-hosted environments. |
Beta Was this translation helpful? Give feedback.
-
oh, this is absurd that one cannot turn off the edge runtime for the middleware. |
Beta Was this translation helpful? Give feedback.
-
any news on this ? |
Beta Was this translation helpful? Give feedback.
-
The fact that only the edge runtime is available is really disappointing. My expectation would be Node.js by default and opt-in to edge, given the limitations. |
Beta Was this translation helpful? Give feedback.
-
Please add the ability to disable edge functions. |
Beta Was this translation helpful? Give feedback.
-
There's already an open issue for this. #46722 unfortunately it's open since March 2023 and no word from the team. |
Beta Was this translation helpful? Give feedback.
-
Deployed the standalone dir to Digital Ocean, because I want to manage my own infrastructure... I get this: /var/www/app/standalone/apps/web
node server.js
node:internal/modules/cjs/loader:1147
throw err;
^
Error: Cannot find module 'styled-jsx/package.json'
Require stack:
- /var/www/app/standalone/apps/web/node_modules/next/dist/server/require-hook.js
- /var/www/app/standalone/apps/web/node_modules/next/dist/server/next.js
- /var/www/app/standalone/apps/web/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
at resolve (node:internal/modules/helpers:187:19)
at Object.<anonymous> (/var/www/app/standalone/apps/web/node_modules/next/dist/server/require-hook.js:38:32)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Module.require (node:internal/modules/cjs/loader:1235:19)
at require (node:internal/modules/helpers:176:18)
at Object.<anonymous> (/var/www/app/standalone/apps/web/node_modules/next/dist/server/next.js:25:1) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/var/www/app/standalone/apps/web/node_modules/next/dist/server/require-hook.js',
'/var/www/app/standalone/apps/web/node_modules/next/dist/server/next.js',
'/var/www/app/standalone/apps/web/server.js'
]
}
Node.js v20.11.1 |
Beta Was this translation helpful? Give feedback.
-
You could just patch the sandbox and run your own function there instead. Of course it's hacky but the whole thing is ridiculous. Running code on node in a js sandbox that emulates Edge... And to make it more ironic, the sandbox already imports some node libraries ( buffer, events and such ) so you can add any library as well with some source edits. I had a project where to get db driver working I just patched the whole thing so there's a dummy middleware to "set things up" and then just run "my own" middleware after it. Fixing this officially should be trivial. try { |
Beta Was this translation helpful? Give feedback.
-
Is there still no update to this ? I want to check for user session using prisma in the middleware and i dont want to use the edge runtime for prisma and next.js |
Beta Was this translation helpful? Give feedback.
-
Kept encountering issues with this while implementing SSO with BoxyHQ. I've essentially been forced into using their cloud-hosted solution. Same deal with Prisma. This needs to be a priority for at least Next 16. Or maybe even 15 to go with the other super obvious fixes. |
Beta Was this translation helpful? Give feedback.
-
The way the things is going, no middleware without edge on Nextjs 15. |
Beta Was this translation helpful? Give feedback.
-
Please free us from edge runtime. It makes absolutely no sense that I deploy Next.js on Kubernetes with Docker, and I'm forced to be limited to edge runtime middleware, while the app is literally running on a Node.js 20.x Alpine image. Let us break the glass here, it's annoying. |
Beta Was this translation helpful? Give feedback.
-
Is there literally no way to disable edge runtime? We can't have a "monorepo" next.js hosted on vercel? |
Beta Was this translation helpful? Give feedback.
-
the only way is changing framework |
Beta Was this translation helpful? Give feedback.
-
The edge runtime is a sad and regrettable constraint that I would've preferred to know about before migrating to Next.js. I was drawn to Next.js's popularity and was eager to work with it, but since I tried to implement a middleware and instrumentation, it now feels like it's working against me. It's grinding my gears and has brought the advancement of certain features to a halt, which I ironically thought would be faster to implement with Next. I would very much like the folks at Vercel to hear us and give us the option to opt out of what should've been an opt-in solution from the start. |
Beta Was this translation helpful? Give feedback.
-
I don't need nextjs middleware anymore, because I don't need nextjs anymore. |
Beta Was this translation helpful? Give feedback.
-
update -- they're working on it |
Beta Was this translation helpful? Give feedback.
-
For everyone who wanna know about the Node runtime and keep up with its updates: #71727 |
Beta Was this translation helpful? Give feedback.
-
Configure Middleware to Use Node.js Runtime Set runtime: 'nodejs' in the middleware configuration to specify that the Node.js runtime should be used instead of the Edge runtime. javascript export async function middleware(req: NextRequest) { export const config = { javascript Verify with Canary Release Since you’re on a canary release, confirm that this behavior persists by running npm update next@canary to ensure you’re on the latest canary version. Canary releases may have recent fixes or changes that improve middleware behavior. Important Notes |
Beta Was this translation helpful? Give feedback.
-
We are working on allowing using the Node.js runtime for Middleware, and it will be included in an upcoming Next.js release. We appreciate your feedback and patience on this issue. We are also exploring a potential new API, called Request Interceptors, that would address some of the feedback here for supporting nested, file-system based middleware. If this is something you are interested in, please comment on the proposal. To prevent additional GitHub notifications and emails, we have a new discussion where you can opt-into notifications as progress is made. Thank you 🙏 |
Beta Was this translation helpful? Give feedback.
We are working on allowing using the Node.js runtime for Middleware, and it will be included in an upcoming Next.js release. We appreciate your feedback and patience on this issue.
We are also exploring a potential new API, called Request Interceptors, that would address some of the feedback here for supporting nested, file-system based middleware. If this is something you are interested in, please comment on the proposal.
To prevent additional GitHub notifications and emails, we have a new discussion where you can opt-into notifications as progress is made.
Thank you 🙏