diff --git a/src/resend.ts b/src/resend.ts index bc2902ba..5e1446d0 100644 --- a/src/resend.ts +++ b/src/resend.ts @@ -7,8 +7,16 @@ import { Emails } from './emails/emails'; import { isResendErrorResponse } from './guards'; import { ErrorResponse } from './interfaces'; -const baseUrl = process.env.RESEND_BASE_URL || 'https://api.resend.com'; -const userAgent = process.env.RESEND_USER_AGENT || `resend-node:${version}`; +const defaultBaseUrl = 'https://api.resend.com'; +const defaultUserAgent = `resend-node:${version}`; +const baseUrl = + typeof process !== 'undefined' && process.env + ? process.env.RESEND_BASE_URL || defaultBaseUrl + : defaultBaseUrl; +const userAgent = + typeof process !== 'undefined' && process.env + ? process.env.RESEND_USER_AGENT || defaultUserAgent + : defaultUserAgent; export class Resend { private readonly headers: Headers; @@ -20,7 +28,9 @@ export class Resend { constructor(readonly key?: string) { if (!key) { - this.key = process.env.RESEND_API_KEY; + if (typeof process !== 'undefined' && process.env) { + this.key = process.env.RESEND_API_KEY; + } if (!this.key) { throw new Error(