medusajs/medusa · warning
No middleware configuration found in ${absolutePath}. Skippi
Error message
No middleware configuration found in ${absolutePath}. Skipping middleware configuration. What it means
The framework's middleware file loader scans src/api/middleware.ts (or middleware files under api/) and expects a default export containing the middleware configuration array. If the file exists but exports no default, the loader warns and skips applying any middleware configuration.
Source
Thrown at packages/core/framework/src/http/middleware-file-loader.ts:60
/**
* Route matchers on which a custom body parser config is used
*/
#bodyParserConfigRoutes: BodyParserConfigRoute[] = []
/**
* Processes the middleware file and returns the middleware and the
* routes config exported by it.
*/
async #processMiddlewareFile(absolutePath: string): Promise<void> {
const middlewareExports = await dynamicImport(absolutePath)
if (isFileSkipped(middlewareExports)) {
return
}
const middlewareConfig = middlewareExports.default
if (!middlewareConfig) {
logger.warn(
`No middleware configuration found in ${absolutePath}. Skipping middleware configuration.`
)
return
}
const routes = middlewareConfig.routes as MiddlewaresConfig["routes"]
if (!routes || !Array.isArray(routes)) {
logger.warn(
`Invalid default export found in ${absolutePath}. Make sure to use "defineMiddlewares" function and export its output.`
)
return
}
const result = routes.reduce<{
bodyParserConfigRoutes: BodyParserConfigRoute[]
additionalDataValidatorRoutes: AdditionalDataValidatorRoute[]
middleware: MiddlewareDescriptor[]
}>(View on GitHub (pinned to 5e06e544a2)
Solutions
- Use a default export in src/api/middleware.ts: `export default defineMiddlewares([...])` or `export default [ ... ]`
- Import defineMiddlewares from @medusajs/framework/http
- Restart the medusa dev server
Example fix
// before (src/api/middleware.ts)
export const middlewares = [
{ matcher: "/admin/*", middlewares: [authenticate()] },
]
// after
import { defineMiddlewares, authenticate } from "@medusajs/framework/http"
export default defineMiddlewares([
{ matcher: "/admin/*", middlewares: [authenticate()] },
]) Defensive patterns
Strategy: validation
Validate before calling
// prebuild check
const src = readFileSync("src/api/middleware.ts", "utf8")
if (!/export\s+default/.test(src)) throw new Error("middleware.ts must have a default export (defineMiddlewares)") Prevention
- Always use `export default defineMiddlewares([...])` in src/api/middleware.ts
- Run the dev server locally and watch startup logs for middleware warnings before deploying
When it happens
Trigger: A middleware.ts in src/api that only uses named exports (e.g. export const middlewares = [...]) or exports the config under a different name.
Common situations: Converting from older Medusa versions where the export shape differed; refactoring removed `export default`.
Related errors
- invalid_data
- invalid_data
- CloudServiceError propagated from non-ok response (body.mess
- Layout file has no default export, skipping.
- Invalid default export found in ${absolutePath}. Make sure t
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/ab0f796772b6fbab.
Report an issue: GitHub.