{"record":{"id":"f74b3739c172228d","repo":"remotion-dev/remotion","slug":"src-must-be-a-string-or-url-when-using-fetchreade","errorCode":null,"errorMessage":"src must be a string or URL when using `fetchReader`","messagePattern":"src must be a string or URL when using `fetchReader`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/readers/from-fetch.ts","lineNumber":334,"sourceCode":"export const fetchReadWholeAsText: ReadWholeAsText = async (src) => {\n\tif (typeof src !== 'string' && src instanceof URL === false) {\n\t\tthrow new Error('src must be a string when using `fetchReader`');\n\t}\n\n\tconst res = await fetch(src);\n\tif (!res.ok) {\n\t\tthrow new Error(`Failed to fetch ${src} (HTTP code: ${res.status})`);\n\t}\n\n\treturn res.text();\n};\n\nexport const fetchCreateAdjacentFileSource: CreateAdjacentFileSource = (\n\trelativePath,\n\tsrc,\n) => {\n\tif (typeof src !== 'string' && src instanceof URL === false) {\n\t\tthrow new Error('src must be a string or URL when using `fetchReader`');\n\t}\n\n\treturn new URL(relativePath, src).toString();\n};\n\nexport const fetchReader: MediaParserReaderInterface = {\n\tread: fetchReadContent,\n\treadWholeAsText: fetchReadWholeAsText,\n\tcreateAdjacentFileSource: fetchCreateAdjacentFileSource,\n\tpreload: fetchPreload,\n};\n","sourceCodeStart":316,"sourceCodeEnd":346,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/readers/from-fetch.ts#L316-L346","documentation":"Thrown by fetchCreateAdjacentFileSource when resolving an auxiliary/adjacent file path relative to a fetch-based media source. The reader constructs a URL via new URL(relativePath, src), which requires src to be a string or URL object. A Blob, File, or other non-URL src cannot be used with the fetch reader's adjacent-file mechanism. This is a type/contract guard ensuring URL resolution works.","triggerScenarios":"Calling parseMedia with srcType 'fetch' (or a reader whose createAdjacentFileSource resolves to fetchCreateAdjacentFileSource) where the passed src is a Blob, File, or other non-string/non-URL value, and the parser subsequently tries to fetch an adjacent file (e.g. a sidecar .vtt, external moov atom, or companion asset referenced relative to the media).","commonSituations":"Swapping a File/Blob-based parseMedia call to the fetch reader without converting src to an object URL. Passing a pre-fetched Response body or Blob URL string that is not a valid URL. Mixing webFileReader expectations into a fetchReader code path.","solutions":["Ensure the src passed to the fetch reader is an absolute http(s) URL string (or URL object) before parseMedia runs, e.g. convert Blobs via URL.createObjectURL(blob).","If you have a File/Blob, use webFileReader (or inputTypeFileReader) instead of fetchReader.","Verify the reader selected by srcType matches the src type: fetchReader expects string|URL, nodeReader expects a string path, webFileReader expects a File/Blob."],"exampleFix":"// before\nawait parseMedia({ src: myBlob, fields: { ... } }); // with fetch reader implied\n\n// after\nconst url = URL.createObjectURL(myBlob);\nawait parseMedia({ src: url, fields: { ... } });","handlingStrategy":"validation","validationCode":"function assertFetchSrc(src: unknown): asserts src is string | URL {\n  if (typeof src !== 'string' && !(src instanceof URL)) {\n    throw new TypeError('fetchReader requires src to be string|URL; got ' + (src as object)?.constructor?.name);\n  }\n}\nassertFetchSrc(src);","typeGuard":"const isFetchSrc = (s: unknown): s is string | URL => typeof s === 'string' || s instanceof URL;","tryCatchPattern":"try { await parseMedia({ src, srcType: 'fetch', fields }); } catch (e) { if (/src must be a string or URL/.test(String((e as Error).message))) { src = URL.createObjectURL(blob); /* retry */ } else throw e; }","preventionTips":["Centralize src-type selection in one helper that returns both src and srcType.","Never pass a Blob/File to the fetch reader; convert to an object URL first.","Document the (srcType, src type) matrix in your wrapper so callers cannot mismatch."],"tags":["media-parser","reader","fetch","type-validation","url"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}