nextjs - ✅(Solved) Fix Proxy file exports issue when custom page extension is used [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#85648Fetched 2026-04-08 02:14:44
View on GitHub
Comments
3
Participants
3
Timeline
10
Reactions
1
Author
Timeline (top)
commented ×3labeled ×2cross-referenced ×1issue_type_added ×1

Error Message

⨯ [Error: The Middleware file "/middleware" must export a function named middleware or a default function.]

Root Cause

I shouldn’t receive this error, because by src/proxy.customExtension.ts exports proxy function correctly

PR fix notes

PR #8: Fix: Middleware deprecation issues

Description (problem / solution / changelog)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

Summary by CodeRabbit

  • Refactor
    • Internal auth/provider initialization updated; no direct user-facing changes.
  • Chores
    • Authentication now reads publishable and secret keys from environment variables and exposes the publishable key to the client build configuration to standardize runtime setup.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Changed files

  • app/layout.tsx (modified, +1/-1)
  • next.config.ts (modified, +3/-0)
  • proxy.ts (renamed, +4/-1)

Code Example

[Error: The Middleware file "/middleware" must export a function named `middleware` or a default function.]

---

import { NextRequest,  } from 'next/server';


export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 12
Binaries:
  Node: 22.17.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.11.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

---

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

---

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default nextConfig;

// proxy.ts

import { NextRequest,  } from 'next/server';

// No errors
export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

// any config
export const config = {
  matcher: ['/:path*'],
};

---

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

// proxy.customExtension.ts

import { NextRequest,  } from 'next/server';

/*
 GET / 404 in 374ms (compile: -44367µs, proxy.ts: 372ms, render: 46ms)
 ⨯ [Error: The Middleware file "/middleware" must export a function named `middleware` or a default function.]
 */
export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

---

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

// proxy.customExtension.ts

import { NextRequest,  } from 'next/server';

// default is added
export default async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Git-I985/next-proxy-exports-issue

To Reproduce

  • Install dependencies (npm install or whatever).
  • Start the dev server (npm run start or your equivalent).
  • Open the app in your browser
  • Check console and terminal for errors

Current vs. Expected behavior

Current behavior

I get the following errors

[Error: The Middleware file "/middleware" must export a function named `middleware` or a default function.]

Expected behavior

I shouldn’t receive this error, because by src/proxy.customExtension.ts exports proxy function correctly

import { NextRequest,  } from 'next/server';


export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

https://nextjs.org/docs/app/api-reference/file-conventions/proxy#proxy-function

The file must export a single function, either as a default export or named proxy. Note that multiple proxy from the same file are not supported.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 12
Binaries:
  Node: 22.17.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.11.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware, Error Handling

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

[!WARNING] The bug is reproducible only when a custom pageExtensions is configured and used.

https://nextjs.org/docs/app/api-reference/config/next-config-js/pageExtensions

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

No errors

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {};

export default nextConfig;

// proxy.ts

import { NextRequest,  } from 'next/server';

// No errors
export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

// any config
export const config = {
  matcher: ['/:path*'],
};

Errors

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

// proxy.customExtension.ts

import { NextRequest,  } from 'next/server';

/*
 GET / 404 in 374ms (compile: -44367µs, proxy.ts: 372ms, render: 46ms)
 ⨯ [Error: The Middleware file "/middleware" must export a function named `middleware` or a default function.]
 */
export async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

Custom extension but not errors, when default export is used

// next.config.ts

import type { NextConfig } from "next";

const nextConfig: NextConfig = {
    pageExtensions: ['tsx', 'ts', 'customExtension.ts', 'customExtension.tsx']
};

export default nextConfig;

// proxy.customExtension.ts

import { NextRequest,  } from 'next/server';

// default is added
export default async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

extent analysis

TL;DR

The issue can be resolved by renaming the exported function in proxy.customExtension.ts to middleware or using a default export.

Guidance

  • The error message indicates that the middleware file must export a function named middleware or a default function, but the current export is named proxy.
  • To fix this, rename the proxy function to middleware in proxy.customExtension.ts.
  • Alternatively, use a default export by adding the default keyword to the proxy function.
  • Verify that the error is resolved by checking the console and terminal for errors after making the changes.

Example

// proxy.customExtension.ts

import { NextRequest } from 'next/server';

export async function middleware(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

Or

// proxy.customExtension.ts

import { NextRequest } from 'next/server';

export default async function proxy(request: NextRequest) {
  await Promise.resolve(12)
}

export const config = {
  matcher: ['/:path*'],
};

Notes

The issue is specific to custom page extensions and the naming of the exported function in the middleware file. The fix should be applied to the specific file causing the error.

Recommendation

Apply the workaround by renaming the exported function to middleware or using a default export, as this is a more straightforward solution that does not require changing the overall project configuration.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING