{"id":"3d2ee896cee8cc35","repo":"webpack/webpack","slug":"invalid-srcset-descriptor-found-in-input-at","errorCode":null,"errorMessage":"Invalid srcset descriptor found in '${input}' at '${desc}'","messagePattern":"Invalid srcset descriptor found in '(.+?)' at '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/html/syntax.js","lineNumber":9079,"sourceCode":"\t\t\t\t}\n\n\t\t\t\t// Anything else, Let error be yes.\n\t\t\t} else {\n\t\t\t\tpError = true;\n\t\t\t}\n\t\t}\n\n\t\t// 15. If error is still no, then append a new image source to candidates whose\n\t\t// URL is url, associated with a width width if not absent and a pixel\n\t\t// density density if not absent. Otherwise, there is a parse error.\n\t\tif (!pError) {\n\t\t\tcandidates.push([\n\t\t\t\t/** @type {string} */ (url),\n\t\t\t\tstart,\n\t\t\t\tstart + /** @type {string} */ (url).length\n\t\t\t]);\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid srcset descriptor found in '${input}' at '${desc}'`\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * @returns {void}\n\t */\n\tfunction tokenizeDescriptor() {\n\t\t// 8.1. Descriptor tokenizer: Skip whitespace\n\t\tcollectCharacters(LEADING_SPACES_REGEXP);\n\n\t\t// 8.2. Let current descriptor be the empty string.\n\t\t// (Tracked as a start offset, `-1` = empty; sliced once per descriptor.)\n\t\tdescriptorStart = -1;\n\n\t\t// 8.3. Let state be in descriptor.\n\t\tstate = \"in descriptor\";","sourceCodeStart":9061,"sourceCodeEnd":9097,"githubUrl":"https://github.com/webpack/webpack/blob/318421ea8ac81371f5171236a6efb63675576528/lib/html/syntax.js#L9061-L9097","documentation":"parseSrcset implements the WHATWG srcset attribute parsing algorithm. After tokenizing a candidate's descriptors (width via 'w', density via 'x', height via 'h'), it validates each; if a descriptor is malformed, duplicated (e.g. two widths), zero-width, negative density, or uses an unknown unit, pError is set and the candidate is rejected with this error naming the offending descriptor and the full input.","triggerScenarios":"An <img srcset='...'> (or any attribute parsed by parseSrcset) contains a candidate whose descriptor is invalid: e.g. srcset='img.jpg 1y', srcset='img.jpg 100w 200w', srcset='img.jpg 0w', srcset='img.jpg -2x'. Encountered during HTML module build when webpack parses the HTML asset graph.","commonSituations":"Hand-written srcset with typos; CMS/templates emitting malformed descriptors; confusing the w (width) and x (density) units; mixing the experimental h descriptor with width.","solutions":["Correct the descriptor: use a single width (e.g. img.jpg 480w), a single density (img.jpg 2x), or a single height (img.jpg 600h) per candidate.","Ensure width and density are not both specified on the same candidate.","Validate srcset values in an HTML linter before feeding the file to webpack."],"exampleFix":"<!-- before -->\n<img srcset=\"img.jpg 100w 200w\">\n<!-- after -->\n<img srcset=\"img.jpg 100w, img.jpg 200w\">","handlingStrategy":"validation","validationCode":"const DESC = /^\\s*\\S+(?:\\s+(?:\\d+[wx]|\\d*\\.?\\d+x|\\d+h))?\\s*$/;\nfunction validateSrcset(value) {\n  return value.split(',').every(c => DESC.test(c));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint srcset attributes in HTML before feeding files to webpack.","Use at most one descriptor (w, x, or h) per candidate.","Never combine width (w) and density (x) on the same candidate."],"tags":["html","srcset","asset-parsing","experiments"],"analyzedSha":"318421ea8ac81371f5171236a6efb63675576528","analyzedAt":"2026-08-03T19:39:56.731Z","schemaVersion":2}