vercel/next.js · error · Error
Image with src "${src}" cannot end with a space or control c
Error message
Image with src "${src}" cannot end with a space or control character. Use src.trimEnd() to remove it or encodeURIComponent(src) to keep it. What it means
Props validation in getImgProps: the src string ends with a space or control character (matched by /[\x00-\x20]$/). Trailing whitespace corrupts the optimized-image request URL, so trimEnd() or encodeURIComponent(src) is required.
Source
Thrown at packages/next/src/shared/lib/get-img-props.ts:534
}
if (typeof heightInt === 'undefined') {
throw new Error(
`Image with src "${src}" is missing required "height" property.`
)
} else if (isNaN(heightInt)) {
throw new Error(
`Image with src "${src}" has invalid "height" property. Expected a numeric value in pixels but received "${height}".`
)
}
// eslint-disable-next-line no-control-regex
if (/^[\x00-\x20]/.test(src)) {
throw new Error(
`Image with src "${src}" cannot start with a space or control character. Use src.trimStart() to remove it or encodeURIComponent(src) to keep it.`
)
}
// eslint-disable-next-line no-control-regex
if (/[\x00-\x20]$/.test(src)) {
throw new Error(
`Image with src "${src}" cannot end with a space or control character. Use src.trimEnd() to remove it or encodeURIComponent(src) to keep it.`
)
}
}
}
if (!VALID_LOADING_VALUES.includes(loading)) {
throw new Error(
`Image with src "${src}" has invalid "loading" property. Provided "${loading}" should be one of ${VALID_LOADING_VALUES.map(
String
).join(',')}.`
)
}
if (priority && loading === 'lazy') {
throw new Error(
`Image with src "${src}" has both "priority" and "loading='lazy'" properties. Only one should be used.`
)
}
if (preload && loading === 'lazy') {View on GitHub (pinned to 0eb3775416)
Solutions
- Trim or encode the trailing whitespace in the image src.
Defensive patterns
Strategy: validation
When it happens
Trigger: next/image src ends with a space or control character.
Common situations: A src string with trailing whitespace passed to next/image.
AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19).
Data as JSON: /api/errors/71bb6d976d848142.
Report an issue: GitHub.