Skip to content
Best Practiceswarn by default recommended preset astro-doctor/require-fetch-default-export

require-fetch-default-export

Require a default export from Astro 7 advanced-routing entrypoints.

Why

Astro 7 reserves src/fetch.ts, src/fetch.js, src/fetch.mjs, and src/fetch.mts for advanced routing. A utility module using one of these names without a default export is loaded as a routing entrypoint and can break development or production startup.

Examples

Incorrect

Reserved file contains only a named utility export

typescript
// src/fetch.ts
export const fetchJson = async (url: string) => {
  const response = await fetch(url)
  return response.json()
}

Correct

Export an advanced-routing handler

typescript
// src/fetch.ts
import type { Fetchable } from 'astro'
import { astro, FetchState } from 'astro/fetch'

export default {
  async fetch(request) {
    return astro(new FetchState(request))
  },
} satisfies Fetchable

Configuration

Project audits are configured in doctor.config.ts:

typescriptdoctor.config.ts
export default {
            rules: {
              'astro-doctor/require-fetch-default-export': 'error', // or 'warn' or 'off'
            },
          }

All rules