{"record":{"id":"cbcace179ae70f3c","repo":"sveltejs/kit","slug":"could-not-locate-file-path-please-move-it-to-b","errorCode":null,"errorMessage":"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.","messagePattern":"Could not locate (.+?)\\. 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\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/enhanced-img/src/vite-plugin.js","lineNumber":139,"sourceCode":"\t\t\t\t\t\tconst width = get_attr_value(node, 'width');\n\t\t\t\t\t\turl += url.includes('?') ? '&' : '?';\n\t\t\t\t\t\tif (sizes && 'raw' in sizes) {\n\t\t\t\t\t\t\turl += 'imgSizes=' + encodeURIComponent(sizes.raw) + '&';\n\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}`);","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/enhanced-img/src/vite-plugin.js#L121-L157","documentation":"When an <img> src cannot be resolved by Vite but a file with that path exists in the static/public directory, enhanced-img throws this longer message: it cannot optimize public-dir assets, so the asset must instead live next to the route or be referenced via a resolvable import.","triggerScenarios":"`update_element` (from RegularElement handling) calls `plugin_context.resolve(url)` which returns undefined, and `existsSync(publicDir + file_path)` is true — i.e. the image was found in the static directory.","commonSituations":"Referencing images as `<img src=\"/static/foo.png\">` or `<img src=\"foo.png\">` where foo.png only exists in the static folder instead of importing it or placing it relative to the route.","solutions":["Move the image out of static/ into the routes directory next to the page and reference it relatively","Import the image in the component and bind the imported URL to src","If the asset truly belongs in static, remove it from enhanced-img optimization expectations and reference it with a leading /static/ path as the message suggests"],"exampleFix":"<!-- before -->\n<img src=\"/static/hero.png\" alt=\"hero\" />\n<!-- after -->\n<script>\nimport hero from './hero.png';\n</script>\n<img src={hero} alt=\"hero\" />","handlingStrategy":"validation","validationCode":"// before building, ensure referenced images resolve outside static/\nconst src = '/static/hero.png';\nif (src.startsWith('/static/') || existsSync(path.join('static', src))) {\n  console.warn('enhanced-img cannot optimize static-dir asset:', src);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Import images in components instead of referencing static paths","Keep optimizable images next to the routes that use them","Never place images you want optimized in the static directory"],"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"}