sveltejs/kit · error · Error
You should change envPrefix (${env_prefix}) to avoid conflic
Error message
You should change envPrefix (${env_prefix}) to avoid conflicts with existing environment variables — unexpectedly saw ${name} What it means
adapter-bun lets you set an env_prefix so only variables with that prefix are exposed to the app. At startup it scans process.env and throws if a prefixed variable exists that is not one of the recognized special variables (like PORT_HEADER). This guards against accidentally leaking or misnaming environment variables that would shadow existing ones.
Source
Thrown at packages/adapter-bun/src/env.js:24
'HOST',
'PORT',
'REUSE_PORT',
'IPV6_ONLY',
'CONNECTION_IDLE_TIMEOUT',
'BODY_SIZE_LIMIT',
'SHUTDOWN_TIMEOUT',
'DEVELOPMENT',
'XFF_DEPTH',
'ADDRESS_HEADER',
'PROTOCOL_HEADER',
'HOST_HEADER',
'PORT_HEADER'
]);
if (env_prefix) {
for (const name in process.env) {
if (name.startsWith(env_prefix) && !expected.has(name.slice(env_prefix.length))) {
throw new Error(
`You should change envPrefix (${env_prefix}) to avoid conflicts with existing environment variables — unexpectedly saw ${name}`
);
}
}
}
/**
* @param {string} name
* @param {string} value
* @param {string} expected
* @returns {never}
*/
function parsing_error(name, value, expected) {
throw new Error(
`Invalid value for environment variable ${env_prefix + name}: ${JSON.stringify(value)} (expected ${expected})`
);
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Change the envPrefix adapter option to a more unique prefix (e.g. 'MYAPP_') so it no longer matches unrelated variables.
- Remove or rename the offending environment variable from your deployment environment.
- If the variable is legitimate, load it through env() so its name is in the expected set.
Example fix
// before
adapterBun({ envPrefix: 'PUBLIC_' }); // PUBLIC_URL exists in env
// after
adapterBun({ envPrefix: 'MYSITE_PUBLIC_' }); Defensive patterns
Strategy: validation
Validate before calling
const prefix = 'MYSITE_PUBLIC_';
const unexpected = Object.keys(process.env).filter(
(k) => k.startsWith(prefix) && !['URL'].includes(k.slice(prefix.length))
);
if (unexpected.length) throw new Error(`Colliding env vars: ${unexpected.join(', ')}`); Prevention
- Use a project-unique env prefix, not a generic one like PUBLIC_ or APP_.
- Audit the deployment environment (CI, host platform) for variables matching your prefix.
- Clean up stale env vars when renaming configuration keys.
When it happens
Trigger: Setting env_prefix to a prefix that matches variables already present in the deployment environment (e.g. envPrefix='PUBLIC_' with PUBLIC_URL set) when the variable is not consumed via env() with an expected name.
Common situations: Choosing a generic prefix like PUBLIC_ or APP_ that collides with host platform or CI environment variables; renaming app code without cleaning up stale prefixed variables left in the environment.
Related errors
- Invalid value for environment variable ${env_prefix + name}:
- You should change envPrefix (${env_prefix}) to avoid conflic
- Invalid value for environment variable ${name}: ${JSON.strin
- Invalid BODY_SIZE_LIMIT: '${env('BODY_SIZE_LIMIT')}'. Please
- Cannot build with ${JSON.stringify(file)} because Bun treats
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/c37edc5e8c870470.
Report an issue: GitHub.