{"record":{"id":"159737bb902df389","repo":"withastro/astro","slug":"the-integration-name-integration-is-trying-to-159737","errorCode":null,"errorMessage":"The \"${integration.name}\" integration is trying to add middleware but did not specify an order.","messagePattern":"The \"(.+?)\" integration is trying to add middleware but did not specify an order\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/integrations/hooks.ts","lineNumber":287,"sourceCode":"\t\t\t\t\t},\n\t\t\t\t\taddDevToolbarApp: (entrypoint) => {\n\t\t\t\t\t\tupdatedSettings.devToolbarApps.push(entrypoint);\n\t\t\t\t\t},\n\t\t\t\t\taddClientDirective: ({ name, entrypoint }) => {\n\t\t\t\t\t\tif (updatedSettings.clientDirectives.has(name) || addedClientDirectives.has(name)) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`The \"${integration.name}\" integration is trying to add the \"${name}\" client directive, but it already exists.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// TODO: this should be performed after astro:config:done\n\t\t\t\t\t\taddedClientDirectives.set(\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tbuildClientDirectiveEntrypoint(name, entrypoint, settings.config.root),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\taddMiddleware: ({ order, entrypoint }) => {\n\t\t\t\t\t\tif (typeof updatedSettings.middlewares[order] === 'undefined') {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`The \"${integration.name}\" integration is trying to add middleware but did not specify an order.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t'middleware',\n\t\t\t\t\t\t\t`The integration ${integration.name} has added middleware that runs ${\n\t\t\t\t\t\t\t\torder === 'pre' ? 'before' : 'after'\n\t\t\t\t\t\t\t} any application middleware you define.`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tupdatedSettings.middlewares[order].push(\n\t\t\t\t\t\t\ttypeof entrypoint === 'string' ? entrypoint : fileURLToPath(entrypoint),\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t\tcreateCodegenDir: () => {\n\t\t\t\t\t\tconst codegenDir = new URL(normalizeCodegenDir(integration.name), settings.dotAstroDir);\n\t\t\t\t\t\tfs.mkdirSync(codegenDir, { recursive: true });\n\t\t\t\t\t\treturn codegenDir;\n\t\t\t\t\t},","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/integrations/hooks.ts#L269-L305","documentation":"`addMiddleware` reads `order` and uses it to index `updatedSettings.middlewares[order]` (which has fixed 'pre'/'post' keys). If `order` is undefined/invalid, `middlewares[order]` is undefined and Astro throws a plain Error telling you the integration did not specify an order.","triggerScenarios":"An integration calls `addMiddleware({ entrypoint })` without `order`, or with an `order` value other than `'pre'` or `'post'`.","commonSituations":"Authoring an integration that adds middleware and omitting the required `order` field; passing `order: undefined` from optional config; misunderstanding the API as order-optional.","solutions":["Provide `order: 'pre'` or `order: 'post'` in the object passed to `addMiddleware`.","Validate the integration's config so `order` is always one of the two allowed strings before calling the hook.","Update third-party integration packages that may target an older, order-optional API."],"exampleFix":"// before\naddMiddleware({ entrypoint: '@my/middleware' })\n\n// after\naddMiddleware({ order: 'pre', entrypoint: '@my/middleware' })","handlingStrategy":"validation","validationCode":"function assertMiddlewareOrder(entry) {\n  if (entry.order !== 'pre' && entry.order !== 'post') {\n    throw new Error('addMiddleware requires order: \"pre\" | \"post\"');\n  }\n}","typeGuard":"function isMiddlewareOrder(value) {\n  return value === 'pre' || value === 'post';\n}","tryCatchPattern":"null","preventionTips":["Always pass order: 'pre' or 'post' to addMiddleware.","Validate integration config before calling the hook.","Update older integrations to the order-required API."],"tags":["integrations","middleware","config"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}