{"record":{"id":"25be961168fce56f","repo":"vercel/next.js","slug":"specified-basepath-should-not-end-with-found","errorCode":null,"errorMessage":"Specified basePath should not end with /, found \"${result.basePath}\"","messagePattern":"Specified basePath should not end with /, found \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/config.ts","lineNumber":633,"sourceCode":"    )\n  }\n\n  if (result.basePath !== '') {\n    if (result.basePath === '/') {\n      throw new Error(\n        `Specified basePath /. basePath has to be either an empty string or a path prefix\"`\n      )\n    }\n\n    if (!result.basePath.startsWith('/')) {\n      throw new Error(\n        `Specified basePath has to start with a /, found \"${result.basePath}\"`\n      )\n    }\n\n    if (result.basePath !== '/') {\n      if (result.basePath.endsWith('/')) {\n        throw new Error(\n          `Specified basePath should not end with /, found \"${result.basePath}\"`\n        )\n      }\n\n      if (result.assetPrefix === '') {\n        result.assetPrefix = result.basePath\n      }\n    }\n  }\n\n  if (result?.images) {\n    const images: ImageConfig = result.images\n\n    if (typeof images !== 'object') {\n      throw new Error(\n        `Specified images should be an object received ${typeof images}.\\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`\n      )\n    }","sourceCodeStart":615,"sourceCodeEnd":651,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L615-L651","documentation":"Next.js validates that a non-root basePath must start with '/' but must NOT end with '/'. This check runs in normalizeConfig during build/dev startup (config.ts:631-636) because a trailing slash on basePath silently breaks route matching, asset URLs, and proxy normalization. The framework treats the trailing slash as a structural error rather than silently stripping it, so routing stays unambiguous.","triggerScenarios":"Setting `basePath: '/docs/'` (or any value ending in '/') in next.config.js/next.config.ts. The guard only fires when basePath !== '' and basePath !== '/', so `basePath: '/'` fails earlier with a different message and `basePath: '/docs'` passes.","commonSituations":"Copy-pasting a deployment sub-path from a URL or nginx location block into basePath (e.g. reverse-proxy config usually shows `/docs/`). Migrating from another framework that tolerates trailing slashes. Editing basePath by hand without realizing the constraint.","solutions":["Remove the trailing slash from basePath, e.g. change `basePath: '/docs/'` to `basePath: '/docs'`.","If you need a trailing slash in URLs, use the separate `trailingSlash: true` option instead of baking it into basePath.","Re-run `next build` or `next dev` to confirm the config loads."],"exampleFix":"// before\nmodule.exports = { basePath: '/docs/' }\n// after\nmodule.exports = { basePath: '/docs', trailingSlash: true }","handlingStrategy":"validation","validationCode":"const cfg = require('./next.config'); const bp = cfg.basePath ?? '';\nif (bp && bp !== '/' && bp.endsWith('/')) {\n  throw new Error('basePath must not end with /. Fix: ' + bp.replace(/\\/+$/, ''));\n}","typeGuard":"function isValidBasePath(bp: unknown): bp is string {\n  return typeof bp === 'string' && (bp === '' || (bp.startsWith('/') && !bp.endsWith('/')));\n}","tryCatchPattern":null,"preventionTips":["Add a unit test asserting basePath never ends with '/' across all environment configs.","Use a config factory that normalizes basePath.trim().replace(/\\/+$/, '') before returning."],"tags":["config","basepath","routing","next-config"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}