{"record":{"id":"0fff1bdce4600f9d","repo":"remotion-dev/remotion","slug":"you-passed-in-a-a-function-to-the-volume-prop-but","errorCode":null,"errorMessage":"You passed in a a function to the volume prop but it did not return a number but a value of type ${typeof evaluated} for frame ${frame}","messagePattern":"You passed in a a function to the volume prop but it did not return a number but a value of type (.+?) for frame (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/volume-prop.ts","lineNumber":22,"sourceCode":"\tframe,\n\tvolume,\n\tmediaVolume = 1,\n}: {\n\tframe: number;\n\tvolume: VolumeProp | undefined;\n\tmediaVolume: number;\n}): number => {\n\tif (typeof volume === 'number') {\n\t\treturn volume * mediaVolume;\n\t}\n\n\tif (typeof volume === 'undefined') {\n\t\treturn Number(mediaVolume);\n\t}\n\n\tconst evaluated = volume(frame) * mediaVolume;\n\tif (typeof evaluated !== 'number') {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a a function to the volume prop but it did not return a number but a value of type ${typeof evaluated} for frame ${frame}`,\n\t\t);\n\t}\n\n\tif (Number.isNaN(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned NaN for frame ${frame}.`,\n\t\t);\n\t}\n\n\tif (!Number.isFinite(evaluated)) {\n\t\tthrow new TypeError(\n\t\t\t`You passed in a function to the volume prop but it returned a non-finite number for frame ${frame}.`,\n\t\t);\n\t}\n\n\treturn Math.max(0, evaluated);\n};","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/volume-prop.ts#L4-L40","documentation":"TypeError thrown by `evaluateVolume` when the `volume` prop is a function but calling `volume(frame)` produced a value whose type is not 'number' (after multiplying by mediaVolume). Remotion's VolumeProp accepts either a number or a function (frame) => number; if the function returns a string, object, undefined, etc., this error fires. Note the original message contains a duplicated 'a a' typo. The evaluated value's typeof is included along with the frame number.","triggerScenarios":"Passing `volume={(frame) => someString}` or any volume callback whose return is not a number for at least one frame in the composition's range. For example returning `undefined` from a branch, a string like '0.5', or forgetting to return from the callback.","commonSituations":"A volume callback with a missing `return` in one branch; returning a value from a map/lookup that is occasionally undefined; migrating from a number volume to a function and leaving a non-number return type.","solutions":["Ensure the volume callback always returns a number for every frame: add explicit `return 0;` in fallback branches.","Annotate the callback as `(frame: number): number => ...` so TypeScript catches non-number returns at compile time.","Unit-test the callback across all frames in the composition duration to find the offending frame noted in the message."],"exampleFix":"// before\n<Video src={s} volume={(f) => {\n  if (f > 30) return 0.5;\n  // missing return -> undefined\n}} />\n\n// after\n<Video src={s} volume={(f: number): number => {\n  if (f > 30) return 0.5;\n  return 0;\n}} />","handlingStrategy":"validation","validationCode":"import type {VolumeProp} from 'remotion';\n\nconst validateVolumeFn = (v: VolumeProp, frames: number[]) => {\n  if (typeof v !== 'function') return;\n  for (const f of frames) {\n    const out = v(f);\n    if (typeof out !== 'number')\n      throw new Error(`volume() returned ${typeof out} at frame ${f}`);\n  }\n};","typeGuard":"const isVolumeFn = (v: unknown): v is ((frame: number) => number) =>\n  typeof v === 'function';","tryCatchPattern":null,"preventionTips":["Annotate volume callbacks as `(frame: number): number => ...`.","Ensure every branch returns a number; add a final `return 0;`.","Test the callback over the full frame range before rendering."],"tags":["audio","volume","validation","typescript"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}