{"record":{"id":"99bd96fccc90ea51","repo":"withastro/astro","slug":"context-next-is-not-implemented-for-serverless-f","errorCode":null,"errorMessage":"`context.next` is not implemented for serverless functions","messagePattern":"`context\\.next` is not implemented for serverless functions","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/netlify/src/index.ts","lineNumber":601,"sourceCode":"\t\t\t},\n\t\t\tip:\n\t\t\t\ttypeof req.headers['x-nf-client-connection-ip'] === 'string'\n\t\t\t\t\t? req.headers['x-nf-client-connection-ip']\n\t\t\t\t\t: (req.socket.remoteAddress ?? '127.0.0.1'),\n\t\t\tserver: {\n\t\t\t\tregion: 'local-dev',\n\t\t\t},\n\t\t\trequestId:\n\t\t\t\ttypeof req.headers['x-nf-request-id'] === 'string'\n\t\t\t\t\t? req.headers['x-nf-request-id']\n\t\t\t\t\t: 'mock-netlify-request-id',\n\t\t\tget cookies(): never {\n\t\t\t\tthrow new Error('Please use Astro.cookies instead.');\n\t\t\t},\n\t\t\tjson: (input) => Response.json(input),\n\t\t\tlog: console.info,\n\t\t\tnext: () => {\n\t\t\t\tthrow new Error('`context.next` is not implemented for serverless functions');\n\t\t\t},\n\t\t\tget params(): never {\n\t\t\t\tthrow new Error(\"context.params don't contain any usable content in Astro.\");\n\t\t\t},\n\t\t\trewrite() {\n\t\t\t\tthrow new Error('context.rewrite is not available in Astro.');\n\t\t\t},\n\t\t};\n\n\t\treturn context;\n\t}\n\n\tlet routes: IntegrationResolvedRoute[];\n\n\treturn {\n\t\tname: '@astrojs/netlify',\n\t\thooks: {\n\t\t\t'astro:config:setup': async ({ config, updateConfig, logger, command }) => {","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/netlify/src/index.ts#L583-L619","documentation":"In the dev mock context, `next` is a function that always throws `'context.next is not implemented for serverless functions'`. Netlify's `context.next()` (used for Next.js-style middleware chaining) has no equivalent in Astro's request lifecycle, and the serverless adapter does not implement it.","triggerScenarios":"Calling `context.next()` inside an Astro handler or middleware in dev. Reusing Netlify Edge Function code that calls `next()` to continue a chain.","commonSituations":"Porting Next-on-Netlify or Edge Function patterns that depend on `context.next()`. Middleware that calls next instead of returning.","solutions":["Do not call `context.next()` in Astro; use middleware's `next()` argument from Astro's own middleware signature instead.","Return a `Response` or call Astro's middleware `next()` rather than Netlify's.","Refactor ported Netlify middleware to Astro middleware conventions."],"exampleFix":"// before (Netlify-style)\nreturn context.next();\n\n// after (Astro middleware)\nreturn next();","handlingStrategy":"validation","validationCode":"// Do not call context.next() in Astro handlers.\n// For middleware, use the Astro-provided next():\nexport function onRequest(context, next) {\n  return next();\n}","typeGuard":"function isAstroMiddlewareNext(fn: unknown): fn is () => Promise<Response> {\n  return typeof fn === 'function';\n}","tryCatchPattern":null,"preventionTips":["Use Astro middleware's `next` argument, not Netlify's `context.next`.","Refactor ported Edge Function code to Astro conventions.","Return a `Response` instead of chaining via next()."],"tags":["netlify","dev-server","middleware","serverless"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}