Patch Next.js core code?

Is there a way to use my own patched Next.js code? Or could/should I fork Next.js and use that?

Next.js v15.5.0 has a core feature (that does a 308 redirect to remove double slashes) that I can’t have in my app. I’ve added a postinstall script which patches next in node_modules, to replace one line of code. This works locally, but not on Vercel. It seems Vercel uses its own optimized Next.js rather than my patched code.

For reference, here’s the patch I made, to get it to work for my specific application. I made this on four different files. I even tried to modify it in node_modules/next/dist/compiled/next-server/server.runtime.prod.jsbut that failed to build on Vercel.

- if (urlNoQuery == null ? void 0 : urlNoQuery.match(/(\\|\/\/)/)) {
+ if (urlNoQuery?.match(/(\\|\/\/)/) && urlNoQuery.length < 44) {

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.