gatsbyjs/gatsby · error · Error
The provided height of
Error message
The provided height of "${height}" is incorrect. Dimensions should be a positive number. What it means
Thrown by calculateImageSizes when the height argument passed to the Gatsby image resolver is a non-positive number (e.g. 0 or a negative value). It is a plain input-validation guard: the polyfill remote-file image sizing math requires positive dimensions to compute layouts.
Solutions
- Ensure height is a positive integer greater than 0.
- Validate dynamically computed heights before passing to the resolver.
- Omit height and provide width instead if only width is known.
- 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
- Validate height is a positive finite number before image transformations.
- Clamp computed heights with Math.max(1, height).
- Test edge cases where layout calculations produce zero or negative heights.
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
- The provided width of
- Either the "width" or "height" argument is required for
- No width or height is given to resize
- Cannot specify both JPG and PNG formats
- RemoteFileNode does not have a mimeType. The field is…
AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13).
Data as JSON: /api/errors/255d9644925220ce.
Report an issue: GitHub.
Appendix: 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)