{"record":{"id":"56a02d71fd108bdc","repo":"sveltejs/kit","slug":"could-not-determine-width-of-image-pathname","errorCode":null,"errorMessage":"Could not determine width of image ${pathname}","messagePattern":"Could not determine width of image (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/enhanced-img/src/index.js","lineNumber":40,"sourceCode":"\t}\n\tif (meta.hasAlpha) {\n\t\treturn 'png';\n\t}\n\treturn 'jpg';\n}\n\nfunction imagetools_plugin() {\n\t/** @type {Partial<import('vite-imagetools').VitePluginOptions>} */\n\tconst imagetools_opts = {\n\t\tdefaultDirectives: async ({ pathname, searchParams: qs }, metadata) => {\n\t\t\tif (!qs.has('enhanced')) return new URLSearchParams();\n\n\t\t\tconst meta = await metadata();\n\t\t\tconst img_width = qs.get('imgWidth');\n\t\t\tconst width = img_width ? parseInt(img_width) : meta.width;\n\n\t\t\tif (!width) {\n\t\t\t\tconsole.warn(`Could not determine width of image ${pathname}`);\n\t\t\t\treturn new URLSearchParams();\n\t\t\t}\n\n\t\t\tconst { widths, kind } = get_widths(width, qs.get('imgSizes'));\n\t\t\treturn new URLSearchParams({\n\t\t\t\tas: 'picture',\n\t\t\t\tformat: `avif;webp;${fallback_format(meta)}`,\n\t\t\t\tw: widths.join(';'),\n\t\t\t\t...(kind === 'x' && !qs.has('w') && { basePixels: widths[0].toString() })\n\t\t\t});\n\t\t},\n\t\tnamedExports: false\n\t};\n\n\t// TODO: should we make formats or sizes configurable besides just letting people override defaultDirectives?\n\t// TODO: generate img rather than picture if only a single format is provided\n\t//     by resolving the directives for the URL in the preprocessor\n\treturn imagetools(imagetools_opts);","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/enhanced-img/src/index.js#L22-L58","documentation":"The enhanced-img imagetools plugin needs an image width to generate a responsive <picture> with multiple srcset widths. It reads the width from the `imgWidth` query parameter or the image's intrinsic metadata; if neither yields a usable width it warns and returns empty search params, skipping width-based transformations for that image.","triggerScenarios":"Importing an image via enhanced-img (imagetools_plugin, wired by imagetools_instance) with directives that require a width (e.g. `?w=` producing a picture/srcset) when the query has no `imgWidth` and sharp's metadata() returns no width for the file.","commonSituations":"Corrupt or zero-byte image files; unsupported formats whose metadata sharp can't parse; SVGs without intrinsic dimensions; passing directives on non-raster assets.","solutions":["Add an explicit `imgWidth` query parameter to the image import (e.g. `?imgWidth=1200&as=picture`).","Verify the image file is valid and opens in an image viewer; replace corrupt assets.","Check the image format is supported by sharp; convert exotic formats to png/jpeg/webp.","For SVGs, provide explicit width/height attributes in the SVG root."],"exampleFix":"// before\nimport img from '$lib/assets/photo.jpg?as=picture';\n// after\nimport img from '$lib/assets/photo.jpg?imgWidth=1600&as=picture';","handlingStrategy":"fallback","validationCode":"import sharp from 'sharp';\nconst meta = await sharp(path).metadata();\nif (!meta.width) console.warn(`${path}: no intrinsic width; pass imgWidth explicitly`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass ?imgWidth= on imports needing responsive srcsets","Validate image assets before committing (open/convert them once)","Convert unsupported formats to webp/png/jpeg","Give SVGs explicit width/height"],"tags":["enhanced-img","vite-plugin","image-processing","build-warning"],"backgroundTag":"image-dimensions-unknown","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}