{"record":{"id":"f496e5b40310dcd4","repo":"vercel/next.js","slug":"unknown-syntax-for-length-expected-value-with-uni","errorCode":null,"errorMessage":"Unknown syntax for length, expected value with unit ({len})","messagePattern":"Unknown syntax for length, expected value with unit \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"turbopack/crates/turbopack-image/src/process/svg.rs","lineNumber":44,"sourceCode":"});\n\nstatic ROOT_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"<svg\\s([^>\"']|\"[^\"]*\"|'[^']*')*>\"#).unwrap());\nstatic WIDTH_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"\\swidth=['\"]([^%]+?)['\"]\"#).unwrap());\nstatic HEIGHT_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"\\sheight=['\"]([^%]+?)['\"]\"#).unwrap());\nstatic VIEW_BOX_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r#\"\\sviewBox=['\"](.+?)['\"]\"#).unwrap());\nstatic VIEW_BOX_CONTENT_REGEX: LazyLock<Regex> = LazyLock::new(|| {\n    Regex::new(r\"^\\s*((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s+((?:\\w|\\.|-)+)\\s*$\")\n        .unwrap()\n});\n\nfn parse_length(len: &str) -> Result<f64> {\n    let captures = UNIT_REGEX\n        .captures(len)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for length, expected value with unit ({len})\"))?;\n    let val = captures[1].parse::<f64>()?;\n    let unit = &captures[2];\n    let unit_scale = UNITS\n        .get(unit)\n        .ok_or_else(|| anyhow!(\"Unknown unit {unit}\"))?;\n    Ok(val * unit_scale)\n}\n\nfn parse_viewbox(viewbox: &str) -> Result<(f64, f64)> {\n    let captures = VIEW_BOX_CONTENT_REGEX\n        .captures(viewbox)\n        .ok_or_else(|| anyhow!(\"Unknown syntax for viewBox ({viewbox})\"))?;\n    let width = parse_length(&captures[3])?;\n    let height = parse_length(&captures[4])?;\n    Ok((width, height))\n}\n\nfn calculate_by_viewbox(","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/turbopack/crates/turbopack-image/src/process/svg.rs#L26-L62","documentation":"Turbopack's SVG dimension calculator (parse_length) expects a width/height value matching `<number><optional-unit>` (e.g. \"100\", \"50px\", \"2in\"). When the attribute value doesn't match that regex — notably percentages, the keyword 'auto', or calc() expressions — parse_length returns this error. It surfaces during image-size inference for SVG assets.","triggerScenarios":"An SVG asset with width=\"100%\", height=\"auto\", width=\"calc(50%)\", or any non-numeric length keyword. The error propagates up from calculate() when both width and height, or viewBox fallback, can't be determined.","commonSituations":"Responsive SVGs authored for the browser using percentage/auto sizing that Turbopack tries to size statically; SVGs exported from design tools with viewport-relative dimensions.","solutions":["Give the SVG explicit numeric width/height (e.g. width=\"64\" height=\"64\") in absolute units.","Provide a viewBox attribute (e.g. viewBox=\"0 0 64 64\") so dimensions can be derived when width/height are relative.","Remove percentage/auto values if the SVG is consumed as a static image asset."],"exampleFix":"<!-- before -->\n<svg width=\"100%\" height=\"auto\" viewBox=\"0 0 64 64\">\n\n<!-- after -->\n<svg width=\"64\" height=\"64\" viewBox=\"0 0 64 64\">","handlingStrategy":"validation","validationCode":"// Validate SVG width/height are numeric-with-optional-unit before using as an asset.\nconst LEN_RE = /^([0-9.]+(?:e-?\\d+)?)(in|cm|em|ex|m|mm|pc|pt|px)?$/;\nfunction isValidLength(v) {\n  return typeof v === 'string' && LEN_RE.test(v.trim());\n}\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Author SVG assets with absolute numeric width/height or a well-formed viewBox.","Avoid percentage/auto/calc() in SVGs consumed as static image assets.","Run an SVG linter over committed icons before bundling."],"tags":["svg","image-size","parsing","dimensions"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}