---
title: NO_FETCH_FROM_MIDDLEWARE
description: Requires that any fetch call that is depended on transitively by Next.js middleware be reviewed and approved before use.
url: "https://vercel.com/docs/conformance/rules/NO_FETCH_FROM_MIDDLEWARE"
last_updated: 2025-03-04
related:
  []
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# NO_FETCH_FROM_MIDDLEWARE

> Conformance is available on Enterprise plans

[Next.js middleware](https://nextjs.org/docs/advanced-features/middleware) runs
code at the Edge. This means that the code is globally distributed. When
middleware makes a `fetch` call, it may be to a backend that is not globally
distributed, in which case the latency of the middleware function will be
really slow. To prevent this, `fetch` calls that can be made from middleware are
flagged and reviewed to make sure that it looks like an appropriate use.

## Example

This check will fail when a `fetch` call is detected from Next.js middleware or
transitive dependencies used by the middleware file.

In this example, there are two files. An experiments file asynchronously
fetches experiments using `fetch`. The middleware file uses the experiments
library to fetch the experiments and then decide to rewrite the URL.

```ts filename="experiments.ts"
export async function getExperiments() {
  const res = await fetch('/experiments');
  return res.json();
}
```

```ts filename="middleware.ts"
export async function middleware(
  request: NextRequest,
  event: NextFetchEvent,
): Promise<Response> {
  const experiments = await getExperiments();

  if (experiments.includes('new-marketing-page)) {
    return NextResponse.rewrite(MARKETING_PAGE_URL);
  }
  return NextResponse.next();
}
```

## How to fix

The correct fix will depend on the specific situation. If the server that is
being called is globally distributed, then this asynchronous call may be okay.
If not, then the code should try to remove the `fetch` statement to avoid
making a request that would add latency to middleware.

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
