{"record":{"id":"ff884ffa8be71a13","repo":"lovell/sharp","slug":"expected-valid-noise-or-background-to-create-a-new","errorCode":null,"errorMessage":"Expected valid noise or background to create a new input image","messagePattern":"Expected valid noise or background to create a new input image","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/input.mjs","lineNumber":384,"sourceCode":"            } else {\n              throw is.invalidParameterError('create.noise.mean', 'number between 0 and 10000', inputOptions.create.noise.mean);\n            }\n          }\n          inputDescriptor.createNoiseSigma = 30;\n          if (is.defined(inputOptions.create.noise.sigma)) {\n            if (is.number(inputOptions.create.noise.sigma) && is.inRange(inputOptions.create.noise.sigma, 0, 10000)) {\n              inputDescriptor.createNoiseSigma = inputOptions.create.noise.sigma;\n            } else {\n              throw is.invalidParameterError('create.noise.sigma', 'number between 0 and 10000', inputOptions.create.noise.sigma);\n            }\n          }\n        } else if (is.defined(inputOptions.create.background)) {\n          if (!is.inRange(inputOptions.create.channels, 3, 4)) {\n            throw is.invalidParameterError('create.channels', 'number between 3 and 4', inputOptions.create.channels);\n          }\n          inputDescriptor.createBackground = this._getBackgroundColourOption(inputOptions.create.background);\n        } else {\n          throw new Error('Expected valid noise or background to create a new input image');\n        }\n        delete inputDescriptor.buffer;\n      } else {\n        throw new Error('Expected valid width, height and channels to create a new input image');\n      }\n    }\n    // Create a new image with text\n    if (is.defined(inputOptions.text)) {\n      if (is.object(inputOptions.text) && is.string(inputOptions.text.text)) {\n        inputDescriptor.textValue = inputOptions.text.text;\n        if (is.defined(inputOptions.text.height) && is.defined(inputOptions.text.dpi)) {\n          throw new Error('Expected only one of dpi or height');\n        }\n        if (is.defined(inputOptions.text.font)) {\n          if (is.string(inputOptions.text.font)) {\n            inputDescriptor.textFont = inputOptions.text.font;\n          } else {\n            throw is.invalidParameterError('text.font', 'string', inputOptions.text.font);","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/lovell/sharp/blob/56676c69180a32b468123e090f87bfee30539b49/lib/input.mjs#L366-L402","documentation":"Thrown when create is used with valid dimensions and channels but neither create.noise nor create.background is provided. A synthetic image must be filled with something — either generated noise or a solid background colour — so omitting both leaves nothing to render. The error is the final else after the noise and background branches.","triggerScenarios":"sharp({ create: { width: 100, height: 100, channels: 3 } }) with no noise and no background. Providing noise/background as undefined explicitly. Building the create object dynamically where both fields ended up unset.","commonSituations":"Copy-paste of a create example with the fill field deleted. Assuming a default fill exists (it does not). Intending a transparent image but forgetting background: { r: 0, g: 0, b: 0, alpha: 0 }.","solutions":["Add a background colour: create: { width, height, channels: 4, background: { r: 0, g: 0, b: 0, alpha: 0 } }.","Or add noise: create: { width, height, channels, noise: { type: 'gaussian', mean: 128, sigma: 30 } }.","Remember channels must be 3-4 for background fills (a separate check enforces this)."],"exampleFix":"// before\nsharp({ create: { width: 100, height: 100, channels: 3 } })\n\n// after\nsharp({ create: { width: 100, height: 100, channels: 4, background: { r: 255, g: 255, b: 255, alpha: 1 } } })","handlingStrategy":"validation","validationCode":"function createFilled({ width, height, channels, background, noise }) {\n  if (!noise && !background) {\n    throw new Error('create requires either noise or background');\n  }\n  if (background && ![3,4].includes(channels)) {\n    throw new Error('background fill requires channels 3 or 4');\n  }\n  return sharp({ create: { width, height, channels, background, noise } });\n}","typeGuard":"function hasCreateFill(create) {\n  return (create.noise !== undefined) || (create.background !== undefined);\n}","tryCatchPattern":null,"preventionTips":["Always specify either background or noise when using create.","Use channels 3-4 with background fills.","For transparent images, set background alpha to 0."],"tags":["create","input","validation","background","noise"],"backgroundTag":null,"analyzedSha":"56676c69180a32b468123e090f87bfee30539b49","analyzedAt":"2026-08-13T04:44:31.201Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}