{"record":{"id":"4ec09e34c08d4dc6","repo":"sveltejs/kit","slug":"could-not-locate-file-path-see-https-vitejs","errorCode":null,"errorMessage":"Could not locate ${file_path}. See https://vitejs.dev/guide/assets for more details on referencing assets.","messagePattern":"Could not locate (.+?)\\. See https://vitejs\\.dev/guide/assets for more details on referencing assets\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/enhanced-img/src/vite-plugin.js","lineNumber":143,"sourceCode":"\t\t\t\t\t\t}\n\t\t\t\t\t\tif (width && 'raw' in width) {\n\t\t\t\t\t\t\turl += 'imgWidth=' + encodeURIComponent(width.raw) + '&';\n\t\t\t\t\t\t}\n\t\t\t\t\t\turl += 'enhanced';\n\t\t\t\t\t}\n\n\t\t\t\t\t// resolves the import so that we can build the entire picture template string and don't\n\t\t\t\t\t// need any logic blocks\n\t\t\t\t\tconst resolved_id = (await plugin_context.resolve(url, filename))?.id;\n\t\t\t\t\tif (!resolved_id) {\n\t\t\t\t\t\tconst query_index = url.indexOf('?');\n\t\t\t\t\t\tconst file_path = query_index >= 0 ? url.substring(0, query_index) : url;\n\t\t\t\t\t\tif (existsSync(path.resolve(vite_config.publicDir, file_path))) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Could not locate ${file_path}. Please move it to be located relative to the page in the routes directory or reference it beginning with /static/. See https://vitejs.dev/guide/assets for more details on referencing assets.`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Could not locate ${file_path}. See https://vitejs.dev/guide/assets for more details on referencing assets.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (OPTIMIZABLE.test(url)) {\n\t\t\t\t\t\tconst image = await process_id(resolved_id, plugin_context, imagetools_plugin);\n\t\t\t\t\t\ts.update(node.start, node.end, img_to_picture(content, node, image));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst metadata = await sharp(resolved_id).metadata();\n\t\t\t\t\t\t// this must come after the await so that we don't hand off processing between getting\n\t\t\t\t\t\t// the imports.size and incrementing the imports.size\n\t\t\t\t\t\tconst name = imports.get(original_url) || '__IMPORTED_ASSET_' + imports.size + '__';\n\t\t\t\t\t\tif (!metadata.width || !metadata.height) {\n\t\t\t\t\t\t\tconsole.warn(`Could not determine intrinsic dimensions for ${resolved_id}`);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst new_markup = `<img ${serialize_img_attributes(content, node.attributes, {\n\t\t\t\t\t\t\tsrc: `{${name}}`,\n\t\t\t\t\t\t\twidth: metadata.width,","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/enhanced-img/src/vite-plugin.js#L125-L161","documentation":"Thrown by the enhanced-img Vite plugin when resolving an image import fails. The plugin builds a query-suffixed URL for the image source and asks Vite to resolve it against the importing file; when resolution returns nothing, it treats the path as a public/ asset and checks the public directory. This error fires when the file exists neither as an importable module asset nor inside the configured publicDir, meaning the src attribute points at a path Vite cannot locate.","triggerScenarios":"`update_element`'s `plugin_context.resolve(url)` returns undefined and `existsSync(path.resolve(publicDir, file_path))` is false — the referenced file is nowhere Vite can find it.","commonSituations":"Typos in image paths, images deleted or renamed, case-sensitivity mismatches on Linux CI, or assets outside both the routes tree and static directory.","solutions":["Fix the path so it matches an existing file relative to the importing route/component","Import the asset explicitly in the module so Vite can resolve it","Check filename casing (Linux is case-sensitive) and that the file wasn't deleted or gitignored"],"exampleFix":"<!-- before -->\n<img src=\"./Hero.png\" alt=\"hero\" />\n<!-- after (file is hero.png) -->\n<img src=\"./hero.png\" alt=\"hero\" />","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nconst file = './hero.png';\nif (!existsSync(new URL(file, import.meta.url).pathname)) {\n  throw new Error(`Image not found: ${file}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify file names/casing match exactly (CI is case-sensitive)","Import assets so missing files fail fast at typecheck/build","Don't gitignore image directories referenced by components"],"tags":["vite","assets","image-optimization","svelte"],"backgroundTag":"unresolved-asset-path","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}