Skip to content

Commit 623f948

Browse files
terencechoclaude
andcommitted
fix(studio): guard import.meta.env for non-Vite consumers
manualEditingAvailability.ts unconditionally reads `import.meta.env`. That's a Vite-only extension; in plain ESM hosts (Next.js / Turbopack, Node, jest in some configs) `import.meta` exists but `import.meta.env` is `undefined`. Reading any property off undefined throws at module evaluation time, so the studio fails to load the moment a non-Vite host imports anything from `@hyperframes/studio`. Guard the read so the module is loadable everywhere; outside Vite, every flag falls back to its declared default, preserving Vite behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 80c88c0 commit 623f948

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

packages/studio/src/components/editor/manualEditingAvailability.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export function resolveStudioBooleanEnvFlag(
2727
return fallback;
2828
}
2929

30-
const env = import.meta.env as StudioFeatureFlagEnv;
30+
// `import.meta.env` is a Vite-only extension. In non-Vite ESM hosts
31+
// (Next.js / Turbopack, Node, jest in some configs) it's undefined,
32+
// and downstream `env[name]` reads would crash. Fall back to `{}` so
33+
// every flag resolves to its declared default outside Vite. Direct
34+
// property access keeps Vite's compile-time transform happy.
35+
const env = (import.meta.env ?? {}) as StudioFeatureFlagEnv;
3136

3237
export const STUDIO_PREVIEW_MANUAL_EDITING_ENABLED = resolveStudioBooleanEnvFlag(
3338
env,

0 commit comments

Comments
 (0)