Registry /
web-framework / nextjs-middleware-chain
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createMiddleware
✓ import { createMiddleware } from 'nextjs-middleware-chain'
✗ const createMiddleware = require('nextjs-middleware-chain')
ESM-only package; CommonJS require will not work.
default export
✓ import mwFactory from './middleware'
✗ import { default as mwFactory } from './middleware'
The package exports only 'createMiddleware' as a named export, NOT a default export. The example in README shows importing a default from a local file, not from the package.
finished route
✓ mwFactory().mwFunction().finish(routeFunction, 'Route Name')
✗ mwFactory().finish(routeFunction)
Chaining requires calling the middleware functions before finish(). Finish() expects a route handler and an optional name.
Shows setup with createMiddleware, then chaining logger and finish in an API route.
// middleware.js
import { createMiddleware } from 'nextjs-middleware-chain';
const logger = (req, res, next) => {
console.log('Request:', req.method, req.url);
return next();
};
const mwFactory = createMiddleware([logger], { useChainOrder: true });
export default mwFactory;
// pages/api/hello.js
import mwFactory from '../../middleware';
const handler = (req, res) => {
res.status(200).json({ message: 'Hello' });
};
export default mwFactory().logger().finish(handler, 'Hello API');
Errors
Common errors & fixes
TypeError: middlewareFunctionsArray is not iterable
createMiddleware expects an array but a single function was passed.
fixWrap the function in an array: createMiddleware([myFn])
TypeError: Cannot read properties of undefined (reading 'finish')
Middleware factory returned undefined because no chainable method was called before finish.
fixEnsure chaining syntax: mwFactory().middlewareFn().finish(handler)
Error: middleware function must return a promise or call next
Middleware function did not call next() or return next().
fixAdd 'return next();' at the end of each middleware function.
Audit
Dependencies
No dependency data recorded yet.