Skip to content

Commit

Permalink
🧑‍💻 Improve invalid environment variable insight on build fail
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Oct 3, 2023
1 parent bf051be commit 8b8a23a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/env/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit 8b8a23a

Please sign in to comment.