vercel/next.js · error · Error

Image with src "${src}" cannot start with a space or control

Error message

Image with src "${src}" cannot start with a space or control character. Use src.trimStart() to remove it or encodeURIComponent(src) to keep it.

What it means

Props validation in getImgProps: the src string starts with a space or control character (matched by /^[\x00-\x20]/). Leading whitespace in URLs gets encoded or mangled by the loader, so the error demands trimStart() or explicit encodeURIComponent() before use.

Source

Thrown at packages/next/src/shared/lib/get-img-props.ts:528

            `Image with src "${src}" is missing required "width" property.`
          )
        } else if (isNaN(widthInt)) {
          throw new Error(
            `Image with src "${src}" has invalid "width" property. Expected a numeric value in pixels but received "${width}".`
          )
        }
        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(',')}.`
      )
    }

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Trim or encode the leading whitespace in the image src.
Defensive patterns

Strategy: validation

When it happens

Trigger: next/image src begins with a space or control character.

Common situations: A src string with leading whitespace passed to next/image.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/bbf2908e384b74d8. Report an issue: GitHub.