Skip to content

Commit 14169aa

Browse files
rr-jimmy-multaniclaudehappy-otter
committed
fix(pluginAddEntry): safe environment access for Vite 5–7 compat
`this.environment` doesn't exist on configResolved/transform hook contexts in Vite 5–7 — accessing it via a typed cast threw TypeError on older versions. Read it through a Record cast so absent properties resolve to undefined instead of throwing. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
1 parent 82544d1 commit 14169aa

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/plugins/pluginAddEntry.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ ${importHelper}(async () => {
312312
// 'ssr' would overwrite entryFiles with the server input (e.g. Nitro's
313313
// SSR entry) and break client injection detection for frameworks like
314314
// TanStack Start that set rollupOptions.input per-environment.
315-
const envName = (this as { environment?: { name?: string } }).environment?.name;
315+
// `this.environment` is Vite 8+ only — Vite 5–7 hook contexts don't have it.
316+
const ctx = this as unknown as Record<string, unknown>;
317+
const envName = (ctx['environment'] as { name?: string } | undefined)?.name;
316318
if (envName && envName !== 'client') return;
317319
const inputOptions = config.build.rollupOptions.input;
318320

@@ -471,7 +473,9 @@ ${importHelper}(async () => {
471473
// Only inject into client-side modules. In Vite 8 multi-environment mode
472474
// this transform also runs for ssr/server environments — injecting there
473475
// would set clientInjected=true and prevent the real client injection.
474-
const transformEnvName = (this as { environment?: { name?: string } }).environment?.name;
476+
const transformCtx = this as unknown as Record<string, unknown>;
477+
const transformEnvName = (transformCtx['environment'] as { name?: string } | undefined)
478+
?.name;
475479
if (transformEnvName && transformEnvName !== 'client') return;
476480
const isVinext = hasPackageDependency('vinext');
477481
if (

0 commit comments

Comments
 (0)