Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.7k
Process and resolve pull request comments#18235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Process and resolve pull request comments#18235
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Co-authored-by: burak.kaya <burak.kaya@sentry.io>
6ea8d90 intofeat/spotlight-environment-variable-supportUh oh!
There was an error while loading.Please reload this page.
size-limit report 📦
|
| if(typeofimport.meta!=='undefined'&&import.meta.env){ | ||
| //@ts-expect-error import.meta.env is typed differently in different environments | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
| constvalue=import.meta.env[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Bug: Vite: Dynamic Env Var Access Not Supported
The dynamic accessimport.meta.env[key] won't work in Vite-based frameworks. Vite performs static replacement at build time for literal property accesses likeimport.meta.env.VITE_VAR, but doesn't create a runtime object that supports bracket notation with variables. This means environment variables in Vite, Astro, and SvelteKit will never be retrieved despite the PR's intent to fix this compatibility issue.
Before submitting a pull request, please take a look at our
Contributing guidelines and verify:
yarn lint) & (yarn test).This PR addresses critical feedback regarding environment variable detection, particularly for Vite-based frameworks.
Key Changes:
packages/browser/src/utils/env.ts: ThegetEnvValuefunction now checks bothprocess.env(for Webpack, Next.js, CRA) andimport.meta.env(for Vite, Astro, SvelteKit). This ensures that environment variables (like those for Spotlight) are correctly detected across a wider range of bundlers and frameworks, fixing a significant compatibility issue.packages/browser/test/utils/env.test.ts: Updated unit tests to focus onprocess.envscenarios. Added a note explaining thatimport.meta.envcannot be unit tested due to its read-only, compile-time nature and is covered by e2e tests.packages/browser/src/utils/spotlightConfig.ts: Added a comment to clarify the explicitreturn undefinedfor readability, noting its optimization in production builds.