Skip to content

Uncaught ReferenceError: process is not defined #49

@sturatcliffe

Description

@sturatcliffe

Hey,

I'm working on a Remix app, and trying to add logging using the @logtail/js package as we need to log from the server actions in Node, and directly from the browser.

The server aspect is working perfectly, but as soon as I try to add client-side logging I get the following error in the console:
image

Remix has a convention of adding a .server.ts suffix to files which should only be included in the server bundles, which is what I've done when using import { Node as Logtail } from '@logtail/js' so I don't believe there is any server specific logic leaking into the client bundle.

The error only appears when I include a React context provider which I've setup for sharing the logger instance to any of my React components in the UI:

import { createContext, useContext, useMemo } from 'react'
import { Browser as Logtail } from '@logtail/js'

type Context = {
	log: Logtail
}

const LogtailContext = createContext<Context | null>(null)

export const useLogtail = () => {
	const context = useContext(LogtailContext)
	if (context == null) throw Error('Use inside LogtailProvider')
	return context
}

type Props = {
	children: React.ReactNode
	sourceToken: string
}

export const LogtailProvider = ({ sourceToken, children }: Props) => {
	const log = useMemo(() => {
		return new Logtail(sourceToken)
	}, [sourceToken])

	return (
		<LogtailContext.Provider
			value={{
				log,
			}}
		>
			{children}
		</LogtailContext.Provider>
	)
}

Any ideas what's happening? We're on v0.3.1 if it helps!

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions