fix: import.meta.ENV being undefined - #42
Conversation
There was a problem hiding this comment.
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.installbehindimport.meta.env?.DEVto avoid crashing whenenvis undefined. - Guard
debug()behindimport.meta.env?.DEVfor 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 |
There was a problem hiding this comment.
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).
| if (!import.meta.env?.DEV) return | |
| if (!import.meta.env || !import.meta.env.DEV) return |
| state: T, | ||
| ): T => { | ||
| if (!import.meta.env.DEV) return state | ||
| if (!import.meta.env?.DEV) return state |
There was a problem hiding this comment.
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.
| if (!import.meta.env?.DEV) return state | |
| if ( | |
| typeof import.meta === 'undefined' || | |
| !import.meta.env || | |
| !import.meta.env.DEV | |
| ) { | |
| return state | |
| } |
| "@vingy/vuebugger": patch | ||
| --- | ||
|
|
||
| fix: import.meta.ENV not being optional |
There was a problem hiding this comment.
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.
| fix: import.meta.ENV not being optional | |
| fix: import.meta.env not being optional |
No description provided.