{"record":{"id":"0e7b455cba1f88be","repo":"vercel/next.js","slug":"specified-basepath-has-to-start-with-a-found","errorCode":null,"errorMessage":"Specified basePath has to start with a /, found \"${result.basePath}\"","messagePattern":"Specified basePath has to start with a /, found \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/next/src/server/config.ts","lineNumber":626,"sourceCode":"      `Specified assetPrefix is not a string, found type \"${typeof result.assetPrefix}\" https://nextjs.org/docs/messages/invalid-assetprefix`\n    )\n  }\n\n  if (typeof result.basePath !== 'string') {\n    throw new Error(\n      `Specified basePath is not a string, found type \"${typeof result.basePath}\"`\n    )\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) {","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/config.ts#L608-L644","documentation":"A non-empty basePath must start with '/' so the router can build absolute internal paths. Normalization throws if basePath is truthy, non-empty, not '/', and does not start with '/'. This catches values like 'docs' or 'app/' that are missing the leading slash.","triggerScenarios":"Setting `basePath: 'docs'`, `basePath: 'app'`, or any non-empty string not beginning with '/'. Checked after the '/' and trailing-slash guards in loadConfig.","commonSituations":"Forgetting the leading slash when copying a sub-path. Reading a path segment from an env var or URL that omits the slash.","solutions":["Prepend a slash: `basePath: '/docs'`","Omit basePath to serve from root"],"exampleFix":"// before\nmodule.exports = { basePath: 'docs' }\n// after\nmodule.exports = { basePath: '/docs' }","handlingStrategy":"validation","validationCode":"if (basePath && basePath !== '' && !basePath.startsWith('/')) {\n  basePath = '/' + basePath\n}","typeGuard":"const isValidBasePath = (v: unknown): v is string =>\n  typeof v === 'string' && (v === '' || v.startsWith('/'))","tryCatchPattern":null,"preventionTips":["Always prefix basePath with a leading slash","Validate basePath shape with a regex like /^\\/[^/]*[^/]$/ before setting it"],"tags":["config","base-path","routing","validation"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}