gatsbyjs/gatsby · error · Error

The provided height of "${height}" is incorrect. Dimensions

Error message

The provided height of "${height}" is incorrect. Dimensions should be a positive number.

What it means

Thrown by calculateImageSizes when a `height` value is provided but is not a positive number. Mirrors the width check — height must be > 0 for the image transformation pipeline.

Source

Thrown at packages/gatsby-plugin-utils/src/polyfill-remote-file/graphql/gatsby-image-resolver.ts:424

  sourceMetadata: ISourceMetadata,
  {
    width,
    height,
    layout,
    fit,
    outputPixelDensities,
    breakpoints,
    aspectRatio,
  }: CalculateImageSizesArgs
): IImageSizes {
  if (width && Number(width) <= 0) {
    throw new Error(
      `The provided width of "${width}" is incorrect. Dimensions should be a positive number.`
    )
  }

  if (height && Number(height) <= 0) {
    throw new Error(
      `The provided height of "${height}" is incorrect. Dimensions should be a positive number.`
    )
  }

  switch (layout) {
    case `fixed`: {
      return calculateFixedImageSizes({
        width,
        height,
        fit,
        sourceMetadata,
        outputPixelDensities,
        aspectRatio,
      })
    }
    case `constrained`: {
      // @ts-ignore - only width or height can be undefined but it doesn't let me type this correctly
      return calculateResponsiveImageSizes({

View on GitHub (pinned to 8b06340921)

Solutions

  1. Ensure height is a positive integer greater than 0.
  2. Validate dynamically computed heights before passing to the resolver.
  3. Omit height and provide width instead if only width is known.
  4. Sanitize input: Math.max(1, height) before calling the resolver.

Example fix

// before
gatsbyImageResolver(source, { layout: 'fixed', height: 0 })
// after
gatsbyImageResolver(source, { layout: 'fixed', height: 200 })
Defensive patterns

Strategy: validation

Validate before calling

// Sanitize height before passing to calculateImageSizes
if (height !== undefined && height !== null) {
  const numericHeight = Number(height)
  if (!Number.isFinite(numericHeight) || numericHeight <= 0) {
    throw new Error(`height must be a positive number, got ${height}`)
  }
}

Type guard

const isPositiveDimension = (val: unknown): val is number =>
  typeof val === 'number' && val > 0 && Number.isFinite(val)

Prevention

When it happens

Trigger: height is truthy but Number(height) <= 0; catches height: 0, height: -50, or invalid string coercion.

Common situations: A query passes height: 0 accidentally, a dynamic height calculation returns a negative value, or the source plugin provides malformed metadata.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/255d9644925220ce. Report an issue: GitHub.