{"record":{"id":"d1f068cb5b414dcd","repo":"remotion-dev/remotion","slug":"parameter-memorysizeinmb-must-not-be-nan-but-is","errorCode":null,"errorMessage":"parameter 'memorySizeInMb' must not be NaN, but is","messagePattern":"parameter 'memorySizeInMb' must not be NaN, but is","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/lambda-client/src/validate-memory-size.ts","lineNumber":11,"sourceCode":"import {MAX_MEMORY, MIN_MEMORY} from './constants';\n\nexport const validateMemorySize = (memorySizeInMb: unknown) => {\n\tif (typeof memorySizeInMb !== 'number') {\n\t\tthrow new TypeError(\n\t\t\t`parameter 'memorySizeInMb' must be a number, got a ${typeof memorySizeInMb}`,\n\t\t);\n\t}\n\n\tif (Number.isNaN(memorySizeInMb)) {\n\t\tthrow new TypeError(`parameter 'memorySizeInMb' must not be NaN, but is`);\n\t}\n\n\tif (!Number.isFinite(memorySizeInMb)) {\n\t\tthrow new TypeError(\n\t\t\t`parameter 'memorySizeInMb' must be finite, but is ${memorySizeInMb}`,\n\t\t);\n\t}\n\n\tif (memorySizeInMb < MIN_MEMORY || memorySizeInMb > MAX_MEMORY) {\n\t\tthrow new TypeError(\n\t\t\t`parameter 'memorySizeInMb' must be between ${MIN_MEMORY} and ${MAX_MEMORY}, but got ${memorySizeInMb}`,\n\t\t);\n\t}\n\n\tif (memorySizeInMb % 1 !== 0) {\n\t\tthrow new TypeError(\n\t\t\t`parameter 'memorySizeInMb' must be an integer but got ${memorySizeInMb}`,\n\t\t);","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda-client/src/validate-memory-size.ts#L1-L29","documentation":"Thrown by validateMemorySize() in @remotion/lambda-client when the memorySizeInMb option is the numeric value NaN. Remotion Lambda must allocate a concrete amount of memory to the render function (between 512 and 10240 MB), and NaN is not an allocatable size. The check runs after the typeof guard, so only a real number that is NaN reaches it.","triggerScenarios":"Calling renderMediaOnLambda() / deploySite() / simulatePermissions() with memorySizeInMb set to the result of a failed Number parse (Number(undefined) === NaN), parseFloat on a non-numeric string, or an arithmetic expression that yields NaN (e.g. 0/0).","commonSituations":"Reading memorySizeInMb from an environment variable or JSON config without coercion, e.g. Number(process.env.REMOTION_MEMORY) where the env var is unset; computing memory from a formula whose divisor is zero; a CLI flag that parses to undefined then gets Number()-ed.","solutions":["Check the upstream source of memorySizeInMb and ensure it is a finite integer before passing it; default to DEFAULT_MEMORY_SIZE (2048) when the value is missing or NaN.","Wrap the read with Number.isFinite() and fall back to a sane default rather than forwarding NaN.","If accepting user input, validate the raw string with /^\\d+$/ before coercing to a number."],"exampleFix":"// before\nconst memorySizeInMb = Number(process.env.REMOTION_MEMORY);\nawait renderMediaOnLambda({memorySizeInMb, ...});\n\n// after\nconst parsed = Number(process.env.REMOTION_MEMORY);\nconst memorySizeInMb = Number.isFinite(parsed) ? parsed : 2048;\nawait renderMediaOnLambda({memorySizeInMb, ...});","handlingStrategy":"type-guard","validationCode":"const safeMemory = (v: unknown): number => {\n  const n = typeof v === 'string' ? Number(v) : v;\n  return typeof n === 'number' && !Number.isNaN(n) && Number.isFinite(n) ? n : 2048;\n};\nawait renderMediaOnLambda({memorySizeInMb: safeMemory(raw), ...});","typeGuard":"const isMemorySize = (v: unknown): v is number =>\n  typeof v === 'number' && !Number.isNaN(v) && Number.isFinite(v) && v >= 512 && v <= 10240 && v % 1 === 0;","tryCatchPattern":null,"preventionTips":["Always coerce and validate memorySizeInMb at the config boundary, not at the Lambda call site.","Default to DEFAULT_MEMORY_SIZE (2048) when input is missing or non-numeric.","Add a unit test that feeds NaN / undefined / Infinity to your config loader and asserts a sane default."],"tags":["lambda","validation","typescript","configuration"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}