vercel/next.js · error
Specified basePath should not end with /, found "${result.ba
Error message
Specified basePath should not end with /, found "${result.basePath}" What it means
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.
Source
Thrown at packages/next/src/server/config.ts:633
)
}
if (result.basePath !== '') {
if (result.basePath === '/') {
throw new Error(
`Specified basePath /. basePath has to be either an empty string or a path prefix"`
)
}
if (!result.basePath.startsWith('/')) {
throw new Error(
`Specified basePath has to start with a /, found "${result.basePath}"`
)
}
if (result.basePath !== '/') {
if (result.basePath.endsWith('/')) {
throw new Error(
`Specified basePath should not end with /, found "${result.basePath}"`
)
}
if (result.assetPrefix === '') {
result.assetPrefix = result.basePath
}
}
}
if (result?.images) {
const images: ImageConfig = result.images
if (typeof images !== 'object') {
throw new Error(
`Specified images should be an object received ${typeof images}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`
)
}View on GitHub (pinned to 0ae8c72462)
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.
Example fix
// before
module.exports = { basePath: '/docs/' }
// after
module.exports = { basePath: '/docs', trailingSlash: true } Defensive patterns
Strategy: validation
Validate before calling
const cfg = require('./next.config'); const bp = cfg.basePath ?? '';
if (bp && bp !== '/' && bp.endsWith('/')) {
throw new Error('basePath must not end with /. Fix: ' + bp.replace(/\/+$/, ''));
} Type guard
function isValidBasePath(bp: unknown): bp is string {
return typeof bp === 'string' && (bp === '' || (bp.startsWith('/') && !bp.endsWith('/')));
} Prevention
- Add a unit test asserting basePath never ends with '/' across all environment configs.
- Use a config factory that normalizes basePath.trim().replace(/\/+$/, '') before returning.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Specified i18n should be an object received ${i18nType}. See
- Failed to resolve pattern "${patterns.join(',')}": ${error.m
- Specified pageExtensions is not an array of strings, found "
- Specified pageExtensions is an empty array. Please update it
- Specified pageExtensions is not an array of strings, found "
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/25be961168fce56f.
Report an issue: GitHub.