From 8b8a23accb4fb1d05c8dbad10faaaf0dbdeca9f8 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Tue, 3 Oct 2023 16:12:04 +0200 Subject: [PATCH] :technologist: Improve invalid environment variable insight on build fail --- packages/env/env.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/env/env.ts b/packages/env/env.ts index 072db6d20c..5cbe00baf8 100644 --- a/packages/env/env.ts +++ b/packages/env/env.ts @@ -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}`