Skip to content

fix: import.meta.ENV being undefined - #42

Merged
vinpogo merged 1 commit into
mainfrom
fix/env-undefined
Mar 3, 2026
Merged

fix: import.meta.ENV being undefined#42
vinpogo merged 1 commit into
mainfrom
fix/env-undefined

Conversation

@vinpogo

@vinpogo vinpogo commented Mar 3, 2026

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 3, 2026 12:52
@vinpogo
vinpogo merged commit 765781e into main Mar 3, 2026
6 checks passed
@vinpogo
vinpogo deleted the fix/env-undefined branch March 3, 2026 12:53
@github-actions github-actions Bot mentioned this pull request Mar 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes vuebugger more resilient in environments where import.meta.env may be missing, preventing runtime failures when the plugin/debug helper are loaded outside a Vite-style build.

Changes:

  • Guard DebugPlugin.install behind import.meta.env?.DEV to avoid crashing when env is undefined.
  • Guard debug() behind import.meta.env?.DEV for the same reason.
  • Add a changeset to release a patch version of @vingy/vuebugger.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/vuebugger/src/index.ts Updates dev-only install guard to tolerate missing import.meta.env.
packages/vuebugger/src/debug.ts Updates dev-only debug guard to tolerate missing import.meta.env.
.changeset/orange-towns-sing.md Adds patch changeset describing the fix.

const plugin: Plugin<[PluginOptions?]> = {
install: (app: App, options?: PluginOptions) => {
if (!import.meta.env.DEV) return
if (!import.meta.env?.DEV) return

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using optional chaining on import.meta.env?.DEV may prevent Vite from doing its usual static replacement / dead-code elimination for import.meta.env.DEV, which can cause the devtools code (and its imports) to remain in production bundles. Consider switching to a short-circuit guard that keeps a plain import.meta.env.DEV access (e.g., check import.meta.env first, then import.meta.env.DEV).

Suggested change
if (!import.meta.env?.DEV) return
if (!import.meta.env || !import.meta.env.DEV) return

Copilot uses AI. Check for mistakes.
state: T,
): T => {
if (!import.meta.env.DEV) return state
if (!import.meta.env?.DEV) return state

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using optional chaining on import.meta.env?.DEV may prevent Vite from statically replacing import.meta.env.DEV and applying dead-code elimination, leaving this debug path (and its imports) in production bundles. Prefer a guard that first checks import.meta.env exists but still references import.meta.env.DEV normally after that check.

Suggested change
if (!import.meta.env?.DEV) return state
if (
typeof import.meta === 'undefined' ||
!import.meta.env ||
!import.meta.env.DEV
) {
return state
}

Copilot uses AI. Check for mistakes.
"@vingy/vuebugger": patch
---

fix: import.meta.ENV not being optional

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changeset message says import.meta.ENV, but the actual property is import.meta.env (lowercase). Updating the text will make the release note accurate and easier to understand.

Suggested change
fix: import.meta.ENV not being optional
fix: import.meta.env not being optional

Copilot uses AI. Check for mistakes.
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.

2 participants