{"record":{"id":"5d64d5a319a6745f","repo":"sveltejs/kit","slug":"invalid-value-for-environment-variable-env-prefi","errorCode":null,"errorMessage":"Invalid value for environment variable ${env_prefix + name}: ${JSON.stringify(value)} (expected ${expected})","messagePattern":"Invalid value for environment variable (.+?): (.+?) \\(expected (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-bun/src/env.js","lineNumber":38,"sourceCode":"\nif (env_prefix) {\n\tfor (const name in process.env) {\n\t\tif (name.startsWith(env_prefix) && !expected.has(name.slice(env_prefix.length))) {\n\t\t\tthrow new Error(\n\t\t\t\t`You should change envPrefix (${env_prefix}) to avoid conflicts with existing environment variables — unexpectedly saw ${name}`\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * @param {string} name\n * @param {string} value\n * @param {string} expected\n * @returns {never}\n */\nfunction parsing_error(name, value, expected) {\n\tthrow new Error(\n\t\t`Invalid value for environment variable ${env_prefix + name}: ${JSON.stringify(value)} (expected ${expected})`\n\t);\n}\n\n/**\n * @template {string | undefined} [T=undefined]\n * @param {string} name\n * @param {T} [fallback]\n * @returns {string | T}\n */\nexport function env(name, fallback) {\n\tconst prefixed = env_prefix + name;\n\treturn prefixed in process.env\n\t\t? /** @type {string} */ (process.env[prefixed])\n\t\t: /** @type {T} */ (fallback);\n}\n\n/** @type {Record<string, boolean>} */","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-bun/src/env.js#L20-L56","documentation":"The typed env helpers (boolean_env, number_env, bytes_env) validate the string value of a prefixed environment variable against the declared type. When the value cannot be parsed (e.g. 'yes' for a boolean, 'abc' for a number), parsing_error throws with the variable name, the raw value, and the expected format.","triggerScenarios":"Calling env('FLAG', 'boolean') where FLAG is set to something unparseable like 'trueish'; env('LIMIT', 'number') with '10s'; env('SIZE', 'bytes') with '10kb ' or other malformed byte strings.","commonSituations":"Typo or wrong-case boolean values (True/YES); human-friendly numbers like '1,000' or '10 MB'; shell quoting leaving stray spaces or quotes in the value.","solutions":["Correct the environment variable value to the expected format shown in the message (e.g. true/false, plain integers, valid byte strings like '512b'/'10kb'/'1mb').","Check for hidden whitespace or stray quotes in the value: run `echo -n \"$VAR\" | xxd` to inspect it.","Unset the variable if it is optional, so the helper's default is used."],"exampleFix":"// before\nORIGIN_LIMIT=\"1,000\" node build\n// after\nORIGIN_LIMIT=1000 node build","handlingStrategy":"validation","validationCode":"function assertNumberEnv(v, name) {\n  if (v === undefined) return;\n  if (!/^-?\\d+(\\.\\d+)?$/.test(v.trim())) throw new Error(`${name} must be a number, got ${JSON.stringify(v)}`);\n}\nassertNumberEnv(process.env.LIMIT, 'LIMIT');","typeGuard":null,"tryCatchPattern":"try {\n  startServer();\n} catch (err) {\n  if (/Invalid value for environment variable/.test(err.message)) {\n    console.error('Fix the env var listed in the message and redeploy');\n  }\n  throw err;\n}","preventionTips":["Document accepted formats (true/false, integers, byte strings) next to each env var.","Validate env vars in CI before deploying.","Beware shell quoting and stray whitespace in .env files."],"tags":["environment","validation","adapter-bun"],"backgroundTag":"invalid-env-var-value","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}