{"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/3578d45d34226d63cff3d261c971c221de6794d2/packages/integrations/netlify/src/index.ts#L583-L619","documentation":"next() on the Netlify Context chains to the next handler in an edge/function pipeline, a concept that does not exist in Astro's serverless functions. The dev Context implements it as a method that always throws, and the same operation is unsupported in the deployed Astro runtime.","triggerScenarios":"Calling context.next() inside an Astro page, endpoint, or middleware when the Netlify adapter is active (thrown by the local-dev stub; the operation has no deployed equivalent either).","commonSituations":"Edge middleware code migrated from Netlify where next() ends middleware and continues the chain; trying to implement fallback handlers by calling next() and reacting to the response.","solutions":["Model the chain as Astro middleware: export onRequest(context, next) and use Astro's next() to continue","Return a Response directly from the handler instead of delegating to a next handler","If you were using next() for auth gating, short-circuit with Astro.redirect before calling next()"],"exampleFix":"// before (Netlify edge style)\nif (!authorized) return context.next();\n// after (Astro middleware)\nexport const onRequest = async (context, next) => {\n  if (!context.locals.authorized) return context.redirect('/login');\n  return next();\n};","handlingStrategy":"fallback","validationCode":"// There is nothing to validate: next() is rejected by design. Replace the call site:\n// Netlify chain style is not portable; use Astro middleware:\nexport const onRequest = async (context, next) => {\n  if (!context.locals.user) return context.redirect('/login');\n  return next();\n};","typeGuard":"function isNetlifyNextAvailable(context: any): boolean {\n  try {\n    return typeof context?.next === 'function' && context.deploy?.context !== 'dev';\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  return await context.next();\n} catch {\n  return new Response('Not Found', { status: 404 });\n}","preventionTips":["Express handler chains as Astro middleware, never via context.next()","Run shared Netlify helpers under astro dev; the stubs surface unsupported calls early","Return explicit Responses instead of delegating to a next handler"],"tags":["netlify","local-dev","context","middleware"],"backgroundTag":"unsupported-api-stub","analyzedSha":"3578d45d34226d63cff3d261c971c221de6794d2","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}