{"record":{"id":"d0b656b58d67a2e8","repo":"medusajs/medusa","slug":"invalid-default-export-found-in-absolutepath-m","errorCode":null,"errorMessage":"Invalid default export found in ${absolutePath}. Make sure to use \"defineMiddlewares\" function and export its output.","messagePattern":"Invalid default export found in (.+?)\\. Make sure to use \"defineMiddlewares\" function and export its output\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/framework/src/http/middleware-file-loader.ts","lineNumber":68,"sourceCode":"   */\n  async #processMiddlewareFile(absolutePath: string): Promise<void> {\n    const middlewareExports = await dynamicImport(absolutePath)\n\n    if (isFileSkipped(middlewareExports)) {\n      return\n    }\n\n    const middlewareConfig = middlewareExports.default\n    if (!middlewareConfig) {\n      logger.warn(\n        `No middleware configuration found in ${absolutePath}. Skipping middleware configuration.`\n      )\n      return\n    }\n\n    const routes = middlewareConfig.routes as MiddlewaresConfig[\"routes\"]\n    if (!routes || !Array.isArray(routes)) {\n      logger.warn(\n        `Invalid default export found in ${absolutePath}. Make sure to use \"defineMiddlewares\" function and export its output.`\n      )\n      return\n    }\n\n    const result = routes.reduce<{\n      bodyParserConfigRoutes: BodyParserConfigRoute[]\n      additionalDataValidatorRoutes: AdditionalDataValidatorRoute[]\n      middleware: MiddlewareDescriptor[]\n    }>(\n      (result, route) => {\n        if (!route.matcher) {\n          throw new Error(\n            `Middleware is missing a \\`matcher\\` field. The 'matcher' field is required when applying middleware. ${JSON.stringify(\n              route,\n              null,\n              2\n            )}`","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/framework/src/http/middleware-file-loader.ts#L50-L86","documentation":"Emitted while Medusa loads middleware files from src/api/middlewares (or a plugin's api/middlewares directory). processMiddlewareFile expects the file's default export to be the result of defineMiddlewares() with a routes array; if routes is missing or not an array, the file is silently skipped with this warning. It is a warning, not a throw, so the rest of the app boots without the middleware.","triggerScenarios":"A file in src/api/middlewares/*.ts whose default export is not wrapped in defineMiddlewares(), or whose object literal has no `routes` key (e.g. exporting { routes: undefined }, a plain function, or an object with only `errorHandler`).","commonSituations":"Copying middleware snippets from older Medusa v1 docs/tutorials that exported a plain config object, typos like `route:` instead of `routes:`, or forgetting the `export default` on the defineMiddlewares() call.","solutions":["Open the file named in ${absolutePath} and wrap the config: export default defineMiddlewares({ routes: [...] })","Verify the key is exactly `routes` and is an array of route entries (method, matcher, middlewares)","Delete the file if it is an accidental/experimental file left in src/api/middlewares","Restart medusa dev — middleware files are only scanned at startup/reload"],"exampleFix":"// before\nexport default {\n  route: [\n    { method: \"GET\", matcher: \"/admin/products\", middlewares: [myMid] },\n  ],\n}\n\n// after\nimport { defineMiddlewares } from \"@medusajs/framework/http\"\nexport default defineMiddlewares({\n  routes: [\n    { method: \"GET\", matcher: \"/admin/products\", middlewares: [myMid] },\n  ],\n})","handlingStrategy":"validation","validationCode":"// before export\nconst config = defineMiddlewares({ routes: [/* ... */] })\nif (!config || !Array.isArray(config.routes)) {\n  throw new Error(\"Invalid middleware config\")\n}\nexport default config","typeGuard":"const isMiddlewaresConfig = (v: unknown): v is { routes: unknown[] } =>\n  typeof v === \"object\" && v !== null && Array.isArray((v as any).routes)","tryCatchPattern":null,"preventionTips":["Always export default defineMiddlewares({ routes: [...] }) from files in src/api/middlewares","Type the export explicitly so TS rejects bad shapes","Keep only middleware files in the middlewares directory"],"tags":["middleware","define-middlewares","bootstrap","config"],"backgroundTag":"invalid-default-export","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}