{"record":{"id":"a26220daaa8a2262","repo":"necolas/react-native-web","slug":"image-asset-with-id-source-could-not-be-foun","errorCode":null,"errorMessage":"Image: asset with ID \"${source}\" could not be found. Please check the image source or packager.","messagePattern":"Image: asset with ID \"(.+?)\" could not be found\\. Please check the image source or packager\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-native-web/src/exports/Image/index.js","lineNumber":126,"sourceCode":"    const { height, width } = getAssetByID(source);\n    return { height, width };\n  } else if (\n    source != null &&\n    !Array.isArray(source) &&\n    typeof source === 'object'\n  ) {\n    const { height, width } = source;\n    return { height, width };\n  }\n}\n\nfunction resolveAssetUri(source): ?string {\n  let uri = null;\n  if (typeof source === 'number') {\n    // get the URI from the packager\n    const asset = getAssetByID(source);\n    if (asset == null) {\n      throw new Error(\n        `Image: asset with ID \"${source}\" could not be found. Please check the image source or packager.`\n      );\n    }\n    let scale = asset.scales[0];\n    if (asset.scales.length > 1) {\n      const preferredScale = PixelRatio.get();\n      // Get the scale which is closest to the preferred scale\n      scale = asset.scales.reduce((prev, curr) =>\n        Math.abs(curr - preferredScale) < Math.abs(prev - preferredScale)\n          ? curr\n          : prev\n      );\n    }\n    const scaleSuffix = scale !== 1 ? `@${scale}x` : '';\n    uri = asset\n      ? `${asset.httpServerLocation}/${asset.name}${scaleSuffix}.${asset.type}`\n      : '';\n  } else if (typeof source === 'string') {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/necolas/react-native-web/blob/a9de220ba9e65bdea540fb5322ffb1da2b0bf442/packages/react-native-web/src/exports/Image/index.js#L108-L144","documentation":"react-native-web's Image resolves numeric sources (require('./img.png') style asset IDs) via getAssetByID, the asset registry populated by the Metro/Haste packager at build time. On web, if a number is passed but no asset with that ID exists in the registry, resolveAssetUri throws because it cannot map the ID to a URI. This indicates the bundler never registered the asset for that module ID.","triggerScenarios":"Passing a raw numeric asset ID as the Image source (e.g. <Image source={12345} />) when getAssetByID(source) returns null/undefined — the ID is not in the asset registry.","commonSituations":"Hard-coding an asset ID copied from another build/environment (IDs are not stable across builds); requiring images in code compiled by a packager that doesn't inject the asset registry (e.g. webpack/vite without an RN asset plugin); stale builds after assets were added or removed; deep-linking or persisting numeric source values.","solutions":["Use require('./image.png') or import at the call site instead of a literal number so the packager registers the asset and injects the registry.","Rebuild/rebundle the app so the asset registry matches the current asset module IDs.","If using a custom bundler, ensure the asset registry plugin (getAssetByID data) is included.","Prefer a remote URI string ({ uri: 'https://...' }) if no local asset is intended."],"exampleFix":"// before\n<Image source={4} />\n// after\nimport img from './assets/logo.png';\n<Image source={img} />","handlingStrategy":"validation","validationCode":"import { Image } from 'react-native';\nimport { getAssetByID } from 'react-native-web/dist/modules/AssetRegistry';\nfunction isValidImageSource(src) {\n  if (typeof src === 'number') return getAssetByID(src) != null;\n  if (typeof src === 'object' && src !== null) return typeof src.uri === 'string';\n  return typeof src === 'string' && src.length > 0;\n}\nif (!isValidImageSource(source)) throw new Error('Unresolvable image source: ' + source);","typeGuard":"const isNumericAssetSource = (s) => typeof s === 'number' && getAssetByID(s) != null;","tryCatchPattern":"try { render(<Image source={src} />); } catch (e) { if (/could not be found/.test(e.message)) logAssetError(src); throw e; }","preventionTips":["Always use require()/import for local assets, never raw numeric IDs","Never persist or copy asset IDs between builds — they are not stable","Ensure your bundler injects the asset registry when compiling RN code for web"],"tags":["react-native-web","image","asset-registry","runtime-error"],"backgroundTag":"unregistered-asset-id","analyzedSha":"a9de220ba9e65bdea540fb5322ffb1da2b0bf442","analyzedAt":"2026-09-01T10:01:09.883Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}