Back to Withastro

Can't load the middleware.

src/content/docs/en/reference/errors/middleware-cant-be-loaded.mdx

latest497 B
Original Source

import DontEditWarning from '~/components/DontEditWarning.astro'

<DontEditWarning />

MiddlewareCantBeLoaded: An unknown error was thrown while loading your middleware.

What went wrong?

Thrown in development mode when middleware throws an error while attempting to loading it.

For example:

ts
import {defineMiddleware} from "astro:middleware";
throw new Error("Error thrown while loading the middleware.")
export const onRequest = defineMiddleware(() => {
  return "string"
});