{"record":{"id":"cb8017b13192baea","repo":"gatsbyjs/gatsby","slug":"fixeddimension-has-to-be-a-positive-int-larger","errorCode":null,"errorMessage":"${fixedDimension} has to be a positive int larger than zero (> 0), now it's ${options[fixedDimension]}","messagePattern":"(.+?) has to be a positive int larger than zero \\(> 0\\), now it's (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sharp/src/index.js","lineNumber":452,"sourceCode":"      reporter\n    )\n    return null\n  }\n\n  const { width, height, density, format } = metadata\n\n  // if no maxWidth is passed, we need to resize the image based on the passed maxHeight\n  const fixedDimension =\n    options.maxWidth === undefined ? `maxHeight` : `maxWidth`\n  const maxWidth = options.maxWidth\n    ? Math.min(options.maxWidth, width)\n    : undefined\n  const maxHeight = options.maxHeight\n    ? Math.min(options.maxHeight, height)\n    : undefined\n\n  if (options[fixedDimension] < 1) {\n    throw new Error(\n      `${fixedDimension} has to be a positive int larger than zero (> 0), now it's ${options[fixedDimension]}`\n    )\n  }\n\n  // Create sizes (in width) for the image if no custom breakpoints are\n  // provided. If the max width of the container for the rendered markdown file\n  // is 800px, the sizes would then be: 200, 400, 800, 1200, 1600.\n  //\n  // This is enough sizes to provide close to the optimal image size for every\n  // device size / screen resolution while (hopefully) not requiring too much\n  // image processing time (Sharp has optimizations thankfully for creating\n  // multiple sizes of the same input file)\n  const fluidSizes = [\n    options[fixedDimension], // ensure maxWidth (or maxHeight) is added\n  ]\n  // use standard breakpoints if no custom breakpoints are specified\n  if (!options.srcSetBreakpoints || !options.srcSetBreakpoints.length) {\n    fluidSizes.push(options[fixedDimension] / 4)","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sharp/src/index.js#L434-L470","documentation":"In gatsby-plugin-sharp's fluidImageSizes / fixedImage pipeline, the code selects which dimension is the controlling one (maxWidth, or maxHeight when maxWidth is undefined) and validates that it is >= 1. Values of 0, negative numbers, or NaN (e.g. from a non-numeric string coerced via arithmetic) trip the check. The dimension must be a positive integer larger than zero.","triggerScenarios":"Passing maxWidth={0}, maxWidth={-100}, or a non-numeric maxWidth to the fluid/resize sharp API or to gatsby-image/StaticImage, e.g. <StaticImage maxWidth={0} /> or sharp({ maxWidth: 'abc' }).","commonSituations":"Computing maxWidth from a CSS variable or window width that is 0 during SSR; passing a prop that defaults to 0; user-uploaded width parsed as string; conditional that yields undefined-then-NaN.","solutions":["Pass a positive integer, e.g. maxWidth={800} (the plugin default).","Coerce and clamp user/SSR input before calling: const w = Math.max(1, parseInt(rawWidth, 10) || 800).","If you genuinely want unconstrained width, use layout='fullWidth' instead of setting maxWidth to 0."],"exampleFix":"// before\n<StaticImage src=\"./hero.jpg\" maxWidth={0} />\n\n// after\n<StaticImage src=\"./hero.jpg\" layout=\"fullWidth\" />\n// or\n<StaticImage src=\"./hero.jpg\" maxWidth={800} />","handlingStrategy":"validation","validationCode":"function assertFixedDimension(options) {\n  const key = options.maxWidth === undefined ? 'maxHeight' : 'maxWidth';\n  const v = Number(options[key]);\n  if (!Number.isInteger(v) || v < 1) {\n    throw new Error(`${key} must be a positive integer > 0, got ${options[key]}`);\n  }\n}","typeGuard":"function isPositiveFixedDimension(options) {\n  const key = options.maxWidth === undefined ? 'maxHeight' : 'maxWidth';\n  const v = Number(options[key]);\n  return Number.isInteger(v) && v > 0;\n}","tryCatchPattern":null,"preventionTips":["Default maxWidth/maxHeight to a sane positive constant (e.g. 800).","Clamp SSR/computed widths: Math.max(1, Math.floor(value)).","Use layout='fullWidth' instead of maxWidth={0} when you want fluid width."],"tags":["gatsby-plugin-sharp","image-processing","validation","dimensions"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}