{"record":{"id":"303bec1887652645","repo":"sveltejs/kit","slug":"invalid-body-size-limit-env-body-size-limit","errorCode":null,"errorMessage":"Invalid BODY_SIZE_LIMIT: '${env('BODY_SIZE_LIMIT')}'. Please provide a numeric value.","messagePattern":"Invalid BODY_SIZE_LIMIT: '(.+?)'\\. Please provide a numeric value\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-node/src/handler.js","lineNumber":30,"sourceCode":"import { parse_as_bytes } from './utils.js';\n\n/** @typedef {(req: IncomingMessage, res: ServerResponse, next: () => void | Promise<void>) => void | Promise<void>} Middleware */\n\nconst origin = ORIGIN;\nconst uncompressed_extensions = UNCOMPRESSED_EXTENSIONS;\nconst prerendered = PRERENDERED;\nconst mime_types = MIME_TYPES;\n\nconst xff_depth = parseInt(env('XFF_DEPTH', '1'));\nconst address_header = env('ADDRESS_HEADER', '').toLowerCase();\nconst protocol_header = env('PROTOCOL_HEADER', '').toLowerCase();\nconst host_header = env('HOST_HEADER', '').toLowerCase();\nconst port_header = env('PORT_HEADER', '').toLowerCase();\n\nconst body_size_limit = parse_as_bytes(env('BODY_SIZE_LIMIT', '512K'));\n\nif (isNaN(body_size_limit)) {\n\tthrow new Error(\n\t\t`Invalid BODY_SIZE_LIMIT: '${env('BODY_SIZE_LIMIT')}'. Please provide a numeric value.`\n\t);\n}\n\nconst asset_dir = `${dir}/client${BASE_PATH}`;\n\nawait server.init({\n\tenv: process.env,\n\tread: (file) => createReadableStream(`${asset_dir}/${file}`)\n});\n\n/**\n * @param {string} path\n * @param {boolean} client\n */\nfunction serve(path, client = false) {\n\treturn fs.existsSync(path)\n\t\t? sirv(path, {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-node/src/handler.js#L12-L48","documentation":"adapter-node parses BODY_SIZE_LIMIT into a byte count via parse_as_bytes (e.g. '512K'). If the resulting value is NaN the server refuses to start because an unbounded/invalid body limit cannot be enforced safely.","triggerScenarios":"Setting BODY_SIZE_LIMIT to a string that parse_as_bytes cannot convert to a number, e.g. '5 MB', 'abc', or an empty string, in handler.js at startup.","commonSituations":"Using unit spellings with spaces or unsupported suffixes ('512 KiB'), decimal values, or copy-pasting a value with hidden characters from docs/CI.","solutions":["Use a valid size literal like '512K', '4M', or a plain byte count like 524288","Check the value for stray spaces/quotes in your .env or deployment config","If using bytes, set a plain integer, e.g. BODY_SIZE_LIMIT=524288"],"exampleFix":"// before\nBODY_SIZE_LIMIT=5 MB\n// after\nBODY_SIZE_LIMIT=5M","handlingStrategy":"validation","validationCode":"const raw = process.env.BODY_SIZE_LIMIT;\nif (raw !== undefined && isNaN(parseAsBytes(raw))) {\n  throw new Error(`BODY_SIZE_LIMIT must be a size like '512K' or bytes, got: ${raw}`);\n}","typeGuard":"function isValidBodySize(v) {\n  return /^\\d+(K|M|G)?$/i.test(String(v).trim());\n}","tryCatchPattern":"try {\n  start();\n} catch (err) {\n  if (String(err.message).includes('Invalid BODY_SIZE_LIMIT')) {\n    console.error('Set BODY_SIZE_LIMIT to e.g. 512K, 4M, or a byte count');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Use documented literals (K/M suffix, no spaces)","Test server boot with the production env locally","Avoid copy-pasting sizes with spaces or decimals"],"tags":["configuration","environment","body-size"],"backgroundTag":"invalid-body-size-limit","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}