Skip to content

Commit

Permalink
fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
dohsimpson committed Feb 19, 2025
1 parent 8ac2ec0 commit b7933ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 0 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import '@/lib/env.server' // startup env var check

import './globals.css'
import { Inter } from 'next/font/google'
import { DM_Sans } from 'next/font/google'
Expand Down
7 changes: 7 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { init } from '@/lib/env.server' // startup env var check

export function register() {
if (typeof window === "undefined") {
init()
}
}
32 changes: 17 additions & 15 deletions lib/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ declare global {
}
}

try {
zodEnv.parse(process.env)
} catch (err) {
if (err instanceof z.ZodError) {
const { fieldErrors } = err.flatten()
const errorMessage = Object.entries(fieldErrors)
.map(([field, errors]) =>
errors ? `${field}: ${errors.join(", ")}` : field,
export function init() {
try {
zodEnv.parse(process.env)
} catch (err) {
if (err instanceof z.ZodError) {
const { fieldErrors } = err.flatten()
const errorMessage = Object.entries(fieldErrors)
.map(([field, errors]) =>
errors ? `${field}: ${errors.join(", ")}` : field,
)
.join("\n ")

console.error(
`Missing environment variables:\n ${errorMessage}`,
)
.join("\n ")

console.error(
`Missing environment variables:\n ${errorMessage}`,
)
process.exit(1)
process.exit(1)
}
}
}
}

0 comments on commit b7933ea

Please sign in to comment.