From f71d83f2d8d857095b211f6a48737e373395991b Mon Sep 17 00:00:00 2001 From: Pete Royce Saldanha Date: Sat, 11 Apr 2026 13:33:43 +0530 Subject: [PATCH] fix(auth): guard process.env access for browser/Vite compatibility Direct access to process.env throws ReferenceError in environments where the global process object does not exist, such as browser builds with Vite, Webpack, or Parcel without a process polyfill. Wrap both process.env accesses in HeaderAuthProvider with a typeof process !== "undefined" guard so the SDK works seamlessly in browser, Node.js, and edge runtimes without requiring a polyfill. Closes #349 --- src/auth/HeaderAuthProvider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/auth/HeaderAuthProvider.ts b/src/auth/HeaderAuthProvider.ts index e8d7304d..eeb68e36 100644 --- a/src/auth/HeaderAuthProvider.ts +++ b/src/auth/HeaderAuthProvider.ts @@ -15,7 +15,7 @@ export class HeaderAuthProvider implements core.AuthProvider { } public static canCreate(options: Partial): boolean { - return options?.[PARAM_KEY] != null || process.env?.[ENV_HEADER_KEY] != null; + return options?.[PARAM_KEY] != null || (typeof process !== "undefined" && process.env?.[ENV_HEADER_KEY] != null); } public async getAuthRequest({ @@ -23,7 +23,7 @@ export class HeaderAuthProvider implements core.AuthProvider { }: { endpointMetadata?: core.EndpointMetadata; } = {}): Promise { - const headerValue = (await core.Supplier.get(this.options[PARAM_KEY])) ?? process.env?.[ENV_HEADER_KEY]; + const headerValue = (await core.Supplier.get(this.options[PARAM_KEY])) ?? (typeof process !== "undefined" ? process.env?.[ENV_HEADER_KEY] : undefined); if (headerValue == null) { throw new errors.DeepgramError({ message: HeaderAuthProvider.AUTH_CONFIG_ERROR_MESSAGE,