2
0

🧑‍💻 Improve invalid environment variable insight on build fail

This commit is contained in:
Baptiste Arnaud
2023-10-03 16:12:04 +02:00
parent bf051bebde
commit 8b8a23accb

11
packages/env/env.ts vendored
View File

@@ -325,6 +325,17 @@ export const env = createEnv({
...posthogEnv.runtimeEnv,
},
skipValidation: typeof window !== 'undefined' && window.__ENV === undefined,
onValidationError(error) {
console.error(
'❌ Invalid environment variables:',
error.flatten().fieldErrors
)
throw new Error(
`Invalid environment variables: ${JSON.stringify(
error.flatten().fieldErrors
)}`
)
},
onInvalidAccess: (variable: string) => {
throw new Error(
`❌ Attempted to access a server-side environment variable on the client: ${variable}`