{"record":{"id":"4be4eb026d7ecbd7","repo":"vercel/next.js","slug":"both-middleware-filename-file-path-relativ","errorCode":null,"errorMessage":"Both ${MIDDLEWARE_FILENAME} file \"./${path.relative(cwd, middlewareFilePath)}\" and ${PROXY_FILENAME} file \"./${path.relative(cwd, proxyFilePath)}\" are detected. Please use \"./${path.relative(cwd, proxyFilePath)}\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy","messagePattern":"Both (.+?) file \"\\./(.+?)\" and (.+?) file \"\\./(.+?)\" are detected\\. Please use \"\\./(.+?)\" only\\. Learn more: https://nextjs\\.org/docs/messages/middleware-to-proxy","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/lib/router-utils/setup-dev-bundler.ts","lineNumber":490,"sourceCode":"        }\n\n        const { name: fileBaseName, dir: fileDir } = path.parse(fileName)\n\n        const isAtConventionLevel =\n          fileDir === dir || fileDir === path.join(dir, 'src')\n\n        if (isAtConventionLevel && fileBaseName === MIDDLEWARE_FILENAME) {\n          middlewareFilePath = fileName\n        }\n        if (isAtConventionLevel && fileBaseName === PROXY_FILENAME) {\n          proxyFilePath = fileName\n        }\n\n        if (middlewareFilePath) {\n          if (proxyFilePath) {\n            const cwd = process.cwd()\n\n            throw new Error(\n              `Both ${MIDDLEWARE_FILENAME} file \"./${path.relative(cwd, middlewareFilePath)}\" and ${PROXY_FILENAME} file \"./${path.relative(cwd, proxyFilePath)}\" are detected. Please use \"./${path.relative(cwd, proxyFilePath)}\" only. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`\n            )\n          }\n          Log.warnOnce(\n            `The \"${MIDDLEWARE_FILENAME}\" file convention is deprecated. Please use \"${PROXY_FILENAME}\" instead.\\n\\n` +\n              `  To migrate automatically, run:\\n` +\n              `  npx @next/codemod@canary middleware-to-proxy .\\n\\n` +\n              `  Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`\n          )\n        }\n\n        const meta = knownFiles.get(fileName)\n\n        const watchTime = fileWatchTimes.get(fileName)\n        const nextWatchTime = meta?.timestamp\n        // If the file is showing up for the first time or the meta.timestamp is changed since last time\n        // Files that were created before we started watching are not considered changed.\n        // If any file was created by Next.js while booting, we assume those changes","sourceCodeStart":472,"sourceCodeEnd":508,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/lib/router-utils/setup-dev-bundler.ts#L472-L508","documentation":"Thrown by the dev bundler setup when both a middleware convention file (middleware.{ts,js,...}) and a proxy convention file (proxy.{ts,js,...}) exist at the convention level. The proxy file replaces middleware; having both is ambiguous and the dev server refuses to start.","triggerScenarios":"After upgrading to a Next.js version that renamed/added the proxy convention, a project has both src/middleware.ts and src/proxy.ts (or root-level equivalents) present. setup-dev-bundler detects both and throws.","commonSituations":"Upgrading Next.js where middleware was deprecated in favor of proxy, and the migration was started but the old middleware file wasn't removed. Codemod run partially.","solutions":["Delete the middleware.{ts,js} file and keep only proxy.{ts,js}, moving its logic over.","Run the official codemod: npx @next/codemod@canary middleware-to-proxy .","Verify only one of the two files remains at the project root or src/ level."],"exampleFix":"// before: both files exist\n// src/middleware.ts\n// src/proxy.ts\n\n// after: remove middleware, keep proxy\n// rm src/middleware.ts\n// src/proxy.ts (contains the migrated logic)","handlingStrategy":"validation","validationCode":"import { glob } from 'glob'\nconst hasMiddleware = glob.sync('{src/,}middleware.{ts,tsx,js,jsx}').length > 0\nconst hasProxy = glob.sync('{src/,}proxy.{ts,tsx,js,jsx}').length > 0\nif (hasMiddleware && hasProxy) throw new Error('Remove middleware file; keep proxy')","typeGuard":"function hasSingleConvention(files: string[]): boolean {\n  const mw = files.some(f => /(^|\\/)middleware\\./.test(f))\n  const px = files.some(f => /(^|\\/)proxy\\./.test(f))\n  return !(mw && px)\n}","tryCatchPattern":"null","preventionTips":["After migrating middleware to proxy, delete the old middleware file.","Run the middleware-to-proxy codemod to automate migration.","Add a CI check that fails if both files exist."],"tags":["middleware","proxy","migration","dev-server"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}