Skip to content

Commit 50296f9

Browse files
ksroda-saclaude
andcommitted
Only validate env vars on dev server, not build
CI has no .env file. Validate on serve only and default to empty strings during build so CI passes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bca2f51 commit 50296f9

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

samples/react/login-pkce/vite.config.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ const exposedEnvVars = [
99
"SCOPES",
1010
];
1111

12-
export default defineConfig(({ mode }) => {
12+
export default defineConfig(({ mode, command }) => {
1313
const env = loadEnv(mode, process.cwd(), "");
14-
const missing = exposedEnvVars.filter((key) => !env[key]);
15-
if (missing.length > 0) {
16-
throw new Error(
17-
`Missing required env vars: ${missing.join(", ")}. Copy .env.example to .env and fill in the values.`,
18-
);
14+
if (command === "serve") {
15+
const missing = exposedEnvVars.filter((key) => !env[key]);
16+
if (missing.length > 0) {
17+
throw new Error(
18+
`Missing required env vars: ${missing.join(", ")}. Copy .env.example to .env and fill in the values.`,
19+
);
20+
}
1921
}
2022
return {
2123
plugins: [react()],
2224
define: Object.fromEntries(
2325
exposedEnvVars.map((key) => [
2426
`import.meta.env.${key}`,
25-
JSON.stringify(env[key]),
27+
JSON.stringify(env[key] ?? ""),
2628
]),
2729
),
2830
server: {

0 commit comments

Comments
 (0)