{"record":{"id":"55d1f2c6a613a444","repo":"gatsbyjs/gatsby","slug":"the-provided-width-of-width-is-incorrect-dim","errorCode":null,"errorMessage":"The provided width of \"${width}\" is incorrect. Dimensions should be a positive number.","messagePattern":"The provided width of \"(.+?)\" is incorrect\\. Dimensions should be a positive number\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-utils/src/polyfill-remote-file/graphql/gatsby-image-resolver.ts","lineNumber":418,"sourceCode":"): string {\n  return images.map(image => `${image.src} ${image.descriptor}`).join(`,`)\n}\n\n// eslint-disable-next-line consistent-return\nfunction calculateImageSizes(\n  sourceMetadata: ISourceMetadata,\n  {\n    width,\n    height,\n    layout,\n    fit,\n    outputPixelDensities,\n    breakpoints,\n    aspectRatio,\n  }: CalculateImageSizesArgs\n): IImageSizes {\n  if (width && Number(width) <= 0) {\n    throw new Error(\n      `The provided width of \"${width}\" is incorrect. Dimensions should be a positive number.`\n    )\n  }\n\n  if (height && Number(height) <= 0) {\n    throw new Error(\n      `The provided height of \"${height}\" is incorrect. Dimensions should be a positive number.`\n    )\n  }\n\n  switch (layout) {\n    case `fixed`: {\n      return calculateFixedImageSizes({\n        width,\n        height,\n        fit,\n        sourceMetadata,\n        outputPixelDensities,","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-utils/src/polyfill-remote-file/graphql/gatsby-image-resolver.ts#L400-L436","documentation":"Thrown by calculateImageSizes in the polyfill-remote-file image utils when a `width` value is provided but is not a positive number (zero or negative). The width must be > 0 because sharp and the image service require valid target dimensions.","triggerScenarios":"width is truthy but Number(width) <= 0; this catches width: 0, width: -100, or width as a string that coerces to a non-positive number.","commonSituations":"A query passes width: 0 by mistake, a computed width from CSS/JS evaluates to zero or negative, or width is passed as an invalid string like '-5'.","solutions":["Ensure width is a positive integer greater than 0 (e.g., 200, 800).","Validate computed width values before passing them to the resolver — guard against 0 or negative results from layout calculations.","If width comes from user input, sanitize it to a minimum positive value (e.g., Math.max(1, width)).","Remove the width argument entirely and provide height instead if only height is known."],"exampleFix":"// before\ngatsbyImageResolver(source, { layout: 'fixed', width: 0 })\n// after\ngatsbyImageResolver(source, { layout: 'fixed', width: 300 })","handlingStrategy":"validation","validationCode":"// Sanitize width before passing to calculateImageSizes\nif (width !== undefined && width !== null) {\n  const numericWidth = Number(width)\n  if (!Number.isFinite(numericWidth) || numericWidth <= 0) {\n    throw new Error(`width must be a positive number, got ${width}`)\n  }\n}","typeGuard":"const isPositiveDimension = (val: unknown): val is number =>\n  typeof val === 'number' && val > 0 && Number.isFinite(val)","tryCatchPattern":null,"preventionTips":["Validate width is a positive finite number before passing to image functions.","Use Math.max(1, width) to clamp computed widths to a safe minimum.","Guard against CSS/layout calculations returning 0 or negative values."],"tags":["gatsby","image","validation","dimensions","sharp"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}