Skip to content

fix(studio): guard import.meta.env for non-Vite bundlers#1049

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/studio-import-meta-env-guard
May 23, 2026
Merged

fix(studio): guard import.meta.env for non-Vite bundlers#1049
miguel-heygen merged 1 commit into
mainfrom
fix/studio-import-meta-env-guard

Conversation

@miguel-heygen
Copy link
Copy Markdown
Collaborator

@miguel-heygen miguel-heygen commented May 23, 2026

Summary

  • Wrap import.meta.env accesses in try-catch — import.meta.env is undefined in Next.js Turbopack/Webpack, causing Cannot read properties of undefined (reading 'VITE_HYPERFRAMES_POSTHOG_KEY') when the studio telemetry module loads
  • Hardcode the PostHog API key and host directly instead of reading from env — they're public write-only values with no need for env override
  • Remove env-override tests that no longer apply, keep opt-out and dev-mode tests

Test plan

  • pnpm --filter @hyperframes/studio exec vitest run src/telemetry/client.test.ts — all 7 tests pass
  • Import @hyperframes/studio in a Next.js (Turbopack) app — no more import.meta.env crash
  • Telemetry opt-out via VITE_HYPERFRAMES_NO_TELEMETRY=1 still works in Vite builds
  • Dev mode (import.meta.env.DEV) still suppresses telemetry in hyperframes preview

import.meta.env is undefined in Next.js Turbopack/Webpack, causing
"Cannot read properties of undefined" when the studio telemetry client
loads. Wrap accesses in try-catch so they gracefully fall back.

Also hardcode the PostHog API key and host — they're public write-only
values with no reason to be overridable via env.
@miguel-heygen miguel-heygen merged commit 793a240 into main May 23, 2026
20 of 33 checks passed
@miguel-heygen miguel-heygen deleted the fix/studio-import-meta-env-guard branch May 23, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant