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

  1. Use a default export in src/api/middleware.ts: `export default defineMiddlewares([...])` or `export default [ ... ]`
  2. Import defineMiddlewares from @medusajs/framework/http
  3. 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

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


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/ab0f796772b6fbab. Report an issue: GitHub.