Nextjs middleware breaks Netlify Forms

Has anyone come across NextJs’s _middleware.js breaking their Netlify Forms?

Even with almost no logic inside the pages/_middleware.js, and just placing a _middleware.js file within pages, my Form breaks, probably because of this build issue:

2:43:38 PM: Skipped moving 7 files because they match middleware, so cannot be deployed to the CDN and will be served from the origin instead.
2:43:38 PM: This is fine, but we're letting you know because it may not be what you expect.
The following middleware matched statically-rendered pages:
2:43:38 PM: - /true/_middleware
2:43:38 PM: ────────────────────────────────────────────────────────────────
2:43:38 PM: The following files matched middleware and were not moved to the CDN:
2:43:38 PM: - index.html
2:43:38 PM: - mypage.html
... and other pages

So I assume adding middleware like this forces all pages - including the one with a Netlify form on it - to be node server rendered… and therefore bypassing however Netlify normally interfaces with, and builds the form?

Note: the pages/_middleware.js works when using this Netlify test, but even when it has no logic like below, the Netlify form break:

import { NextRequest, NextResponse } from 'next/server'

export function middleware(req) {


Hi @slowsun,

You would have to add a static version of your HTML form in the site as explained here:

(point 2 of the linked heading).

1 Like