A lightweight middleware pipeline for Next.js applications, enabling developers to add reusable middleware functions that execute before page rendering. Current stable version is 0.0.1, with no frequent release cadence. Key differentiators: simple API using a pipeline pattern, designed specifically for Next.js pages directory. It allows chaining multiple async middleware functions that can inject props into pages.
npm install next-middlewareNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup: import Middleware, create pipeline, add async middleware that fetches data, and export build method.
Ensure each middleware returns a plain object with the props to inject.
Pin version in package.json and test upgrades thoroughly.
Use Next.js middleware feature for App Router instead.
Ensure you instantiate correctly: const middleware = new Middleware(); then add at least one middleware before exporting .build.
Switch to import statement: import Middleware from 'next-middleware';