deepgram-js-sdk icon indicating copy to clipboard operation
deepgram-js-sdk copied to clipboard

Direct call to process.env in Abstract Client

Open mattkenefick opened this issue 1 year ago • 1 comments

What is the current behavior?

Direct calls to the global process object looking for an API key in the AbstractClient

Steps to reproduce

Run it in an environment without process

Expected behavior

Gracefully ignore the process object if it does not exist.

Please tell us about your environment

I've included @deepgram/sdk into a TypeScript SDK that compiles out for web and node environments. When using the SDK in a web environment, the app throws an error because process.env doesn't exist; I'd imagine you'd run into that for import.meta environments as well, like Vite.

Other information

I added a polyfill for it in my sdk for the time being.

(() => {
	const globalScope: any = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : {};

	if (!globalScope.process) {
		globalScope.process = {};
	}

	if (!globalScope.process.env) {
		globalScope.process.env = {};
	}
})();

mattkenefick avatar Dec 10 '24 15:12 mattkenefick

Good catch, surprised this got through...

lukeocodes avatar Dec 30 '24 15:12 lukeocodes