/nemo:nemo-debuggingfrom NEMO for Next.js
Debug and test @zanreal/nemo middleware issues: routes not running, responses ignored, 401/redirect lost, headers/cookies missing, storage leaks, and unit tests with NextRequest.
Ships in NEMO for Next.js. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Work from the symptom table first, then use the debug options, then write a test that reproduces it.
| Symptom | Likely cause | Fix |
|---|---|---|
Route for /foo does not run on /foo/bar | A top-level function or array key matches the exact path only | Use "/foo/:path*" or a nested object |
| Nested child runs on deeper paths than expected | Nested keys match as prefixes ("/a": { "/b": fn } runs on /a/b/c) | Check request.nextUrl.pathname in the child, or use a top-level key for the exact path |
"/Pricing" does not run on /pricing | Plain paths are compared case sensitively | Use the exact case, or a pattern (patterns are case insensitive) |
"/" route does not run on other pages | "/" is exact root only | Use globalMiddleware.before for every request |
| Route never runs, no exception | Invalid pattern: NEMO prints Error creating regexp for pattern with console.error and the route never matches. Common: /api{/*path} (v8 syntax), (!api) | Use path-to-regexp v6 syntax, see nemo-middleware-patterns/references/matching.md |
| Route never runs for assets or an API path | config.matcher excludes the path so Next.js never calls the proxy | Fix the matcher |
new NextResponse("...", { status: 401 }) has no effect, request continues | A NextResponse without rewrite, Location or JSON type continues the chain | Return new Response(...) or NextResponse.json(...) |
| Redirect throws or goes nowhere | Relative URL | NextResponse.redirect(new URL("/login", request.url)) |
| Later middleware does not see a header | Header set on a response that stopped the chain, or set after the redirect | Set request.headers.set(...) before, in an earlier middleware |
Page cannot read header with headers() | Header set only on the response, not on the request | Set it with request.headers.set(...), NEMO forwards request header changes |
| Cookie lost on redirect | Cookie set on an unrelated NextResponse, not returned | Set on the response you return, or on a continuing response from an earlier middleware |
| Data from one request appears in another | On 3.0.2 and older the default storage is shared by all requests of that createNEMO (security issue). Fixed in the next release: the default is per request. A ready-made instance (storage: new Adapter()) is still shared | Upgrade; on 3.0.2 and older pass storage: () => new MemoryStorageAdapter(). Always prefer a factory |
event.log() prints nothing, even with debug: true | Check that debug: true is in the third argument of createNEMO. On 3.0.2 and older event.log is not wired to debug inside chains (fixed in the next release) | Upgrade; on 3.0.2 and older use event.warn / event.error or console.log |
Work started with event.waitUntil is cut off | On 3.0.2 and older waitUntil is not forwarded to the platform (fixed in the next release) | Upgrade; on 3.0.2 and older use after() from next/server |
req.params is undefined | It does not exist | event.params (or event.getParams(...)) |
StorageAdapter import fails | Not exported from the main entry | import { StorageAdapter } from "@zanreal/nemo/storage" |
NemoMiddlewareError: Middleware execution failed | A middleware threw and silent is false | Read error.originalError (the thrown value) and error.metadata (chain, pathname, routeKey, index); the message also names chain, path, route key and index; fix, or handle it with errorHandler |
| Next.js 16 ignores the file | Wrong name or export | proxy.ts with export const proxy, or legacy middleware.ts with export const middleware |
import { createNEMO } from "@zanreal/nemo";
import { NextResponse } from "next/server";
export const proxy = createNEMO(
{ "/api/:path*": () => {} },
undefined,
{
debug: true, // internal logs: matched routes, execution, errors
enableTiming: true, // time per chain (before/main/after)
silent: false, // true: swallow errors and continue instead of throwing
errorHandler: (error, metadata) => {
console.error("NEMO failed", metadata.chain, metadata.routeKey, metadata.index, error);
// return a response to use it, or nothing to fall back to throw/silent behavior
return NextResponse.json({ error: "Internal error" }, { status: 500 });
},
},
);
Error flow: a thrown error goes to errorHandler(error, metadata). A truthy return value becomes the response. Otherwise silent: false throws NemoMiddlewareError, silent: true continues with the next middleware.
metadata is { chain: "before" | "main" | "after"; index: number; pathname: string; routeKey: string; nestLevel?: number }.
Turn debug off in production unless you need it, it is verbose.
request.headers.set("x-hit-a", "1").x-middleware-request-x-hit-a in tests).Call the handler directly with a NextRequest and a stub event. No server needed. Templates for bun, vitest and jest are in references/testing.md. Core shape:
import { NextRequest, type NextFetchEvent } from "next/server";
import { createNEMO } from "@zanreal/nemo";
const event = { waitUntil: () => {} } as unknown as NextFetchEvent;
const proxy = createNEMO({ "/dashboard/:path*": () => Response.redirect("http://localhost/login") });
const res = await proxy(new NextRequest("http://localhost/dashboard/x"), event);
// res?.status === 302, res?.headers.get("location") === "http://localhost/login"
What to assert:
res.status and res.headers.get("location")res.headers.get("x-middleware-rewrite")res.statusx-foo: res.headers.get("x-middleware-request-x-foo")res.headers.get("x-foo")NextResponse.next()-style response with header x-middleware-next: 1What SKILL.md sets; muted values are Claude Code's defaults
4 skills in this plugin
/nemo-middleware-patternsWrite and organize @zanreal/nemo middleware - chains, nested and parameterized routes, global before/after, shared storage, redirects, rewrites, header and cookie forwarding, auth gating, i18n, event.skip. Use when adding or changing logic inside a createNEMO config, choosing how to stop or continue a chain, or working out why a NEMO middleware does or does not run./nemo-migrateMigrate to @zanreal/nemo from a single Next.js middleware.ts or proxy.ts, from the old @rescale/nemo package (with the nemo-codemod), or from the deprecated createMiddleware API. Use when the user mentions @rescale/nemo, the NEMO codemod, a Next.js 16 middleware-to-proxy rename, wants to split one large middleware into per-route functions, or sees a createMiddleware deprecation warning./nemo-npx claudepluginhub zanreal-labs/nemo --plugin nemoOther plugins' skills for the same job