From 6fd08a417d1ff893b7939f42c8d03b8ebd9d6e4c Mon Sep 17 00:00:00 2001 From: Arne Bahlo Date: Mon, 26 Jun 2023 12:48:12 +0200 Subject: [PATCH] Fake process.env for browsers Otherwise we get this: > Uncaught ReferenceError: process is not defined --- packages/js/src/httpClient.ts | 4 ++++ packages/pino/src/index.ts | 4 ++++ packages/winston/src/index.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/packages/js/src/httpClient.ts b/packages/js/src/httpClient.ts index 60fc8982..9f25b84e 100644 --- a/packages/js/src/httpClient.ts +++ b/packages/js/src/httpClient.ts @@ -9,6 +9,10 @@ export interface ClientOptions { orgId?: string; } +// The browsers don't have process.env, fake it +const process: { env: Record } = + typeof window === 'undefined' ? global.process : { env: {} }; + export default abstract class HTTPClient { protected readonly client: FetchClient; diff --git a/packages/pino/src/index.ts b/packages/pino/src/index.ts index 63e2a758..7d306dd9 100644 --- a/packages/pino/src/index.ts +++ b/packages/pino/src/index.ts @@ -1,6 +1,10 @@ import build from 'pino-abstract-transport'; import { Axiom, ClientOptions } from '@axiomhq/js'; +// The browsers don't have process.env, fake it +const process: { env: Record } = + typeof window === 'undefined' ? global.process : { env: {} }; + export enum AxiomEventLevel { Trace = 'trace', Debug = 'debug', diff --git a/packages/winston/src/index.ts b/packages/winston/src/index.ts index 51ddcd6d..aa13cac4 100644 --- a/packages/winston/src/index.ts +++ b/packages/winston/src/index.ts @@ -2,6 +2,10 @@ import Transport, { TransportStreamOptions } from 'winston-transport'; import { AxiomWithoutBatching } from '@axiomhq/js'; +// The browsers don't have process.env, fake it +const process: { env: Record } = + typeof window === 'undefined' ? global.process : { env: {} }; + export interface WinstonOptions extends TransportStreamOptions { dataset?: string; token?: string;