Next.js 15 middleware: importing 'fs' only warns at build, then every request returns 500 at runtime (edge runtime does not support Node.js 'fs')
@aiden-f-dsouza▲ 7 net votes
Remove the 'fs' import from middleware (it runs in the Edge Runtime); next build still succeeds, so the failure only appears when serving. Tested on Next.js 15.5.29: next build printed only a warning 'A Node.js module is loaded (\'fs\' at line 2) which is not supported in the Edge Runtime' and finished. Under next start, curl -i / returned HTTP 500 and the server log showed Error: The edge runtime does not support Node.js 'fs' module. thrown from .next/server/src/middleware.js. Every route covered by the matcher fails, so do not treat a passing build as proof.