{"record":{"id":"a5be754f4ce4d5be","repo":"remotion-dev/remotion","slug":"null-was-passed-to-staticfile","errorCode":null,"errorMessage":"null was passed to staticFile()","messagePattern":"null was passed to staticFile\\(\\)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/static-file.ts","lineNumber":93,"sourceCode":"};\n\nconst encodeBySplitting = (path: string): string => {\n\tconst splitBySlash = path.split('/');\n\n\tconst encodedArray = splitBySlash.map((element) => {\n\t\treturn encodeURIComponent(element);\n\t});\n\tconst merged = encodedArray.join('/');\n\treturn merged;\n};\n\n/*\n * @description Reference a file from the public/ folder. If the file does not appear in the autocomplete, type the path manually.\n * @see [Documentation](https://www.remotion.dev/docs/staticfile)\n */\nexport const staticFile = (path: string) => {\n\tif (path === null) {\n\t\tthrow new TypeError('null was passed to staticFile()');\n\t}\n\n\tif (typeof path === 'undefined') {\n\t\tthrow new TypeError('undefined was passed to staticFile()');\n\t}\n\n\tif (path.startsWith('http://') || path.startsWith('https://')) {\n\t\tthrow new TypeError(\n\t\t\t`staticFile() does not support remote URLs - got \"${path}\". Instead, pass the URL without wrapping it in staticFile(). See: https://remotion.dev/docs/staticfile-remote-urls`,\n\t\t);\n\t}\n\n\tif (path.startsWith('..') || path.startsWith('./')) {\n\t\tthrow new TypeError(\n\t\t\t`staticFile() does not support relative paths - got \"${path}\". Instead, pass the name of a file that is inside the public/ folder. See: https://remotion.dev/docs/staticfile-relative-paths`,\n\t\t);\n\t}\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/static-file.ts#L75-L111","documentation":"staticFile() expects a string path to a file in the public/ folder. This guard catches a literal `null` argument. Although TypeScript types the parameter as string, null can reach the call through loose typing, JSON data, or `any`-typed values, so the runtime check exists as a safety net with a clear error message.","triggerScenarios":"Calling `staticFile(null)`, passing a variable that is null because a lookup failed (e.g. `staticFile(map[key])` where the key is absent), or feeding `JSON.parse` output that contains null.","commonSituations":"Optional config objects where a field is null instead of omitted; data-driven renders where an asset key is missing; interop with untyped JavaScript modules.","solutions":["Ensure the argument is a string; default or fallback before calling staticFile().","Filter out null entries when mapping over data, e.g. `paths.filter(Boolean).map(staticFile)`.","Tighten the upstream type so null cannot flow into the call."],"exampleFix":"// before\nconst src = staticFile(assetMap[name]);\n\n// after\nconst path = assetMap[name];\nif (path === null || path === undefined) {\n  throw new Error(`missing asset for ${name}`);\n}\nconst src = staticFile(path);","handlingStrategy":"validation","validationCode":"const resolveAsset = (path: string | null | undefined) => {\n  if (path === null || path === undefined) {\n    throw new Error('asset path is missing');\n  }\n  return staticFile(path);\n};","typeGuard":"const isNonNullString = (v: unknown): v is string =>\n  typeof v === 'string' && v.length > 0;","tryCatchPattern":null,"preventionTips":["Type asset paths as `string`, not `string | null`.","Filter null entries before mapping: `paths.filter((p): p is string => !!p).map(staticFile)`.","Validate config objects that carry asset paths before render."],"tags":["staticfile","assets","null","validation","type-safety"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}