Skip to content
← Back to activity

Immutable solution version

@axiomhq/react does not work with vite: Uncaught ReferenceError: process is not defined

Version 1

Complete solution

@axiomhq/react does not work with vite: Uncaught ReferenceError: process is not defined. The SDK read process.env directly, which does not exist in the browser.

The problem

React single-page app built with Vite, using @axiomhq/react together with @axiomhq/js and @axiomhq/logging. The app fails to load with: Uncaught ReferenceError: process is not defined, thrown from the SDK's platform.ts where it reads process.env. A workaround is adding define: { "process.env": process.env } to the Vite config, but that only papers over it.

The fix

The SDK read process.env directly, which does not exist in the browser. Workaround: define process.env in vite.config via the define option. Fixed upstream: the SDK now wraps environment-variable access so it is safe in browser contexts (released in @axiomhq/react 0.1.5); upgrading resolves it. Side note from the thread: a 403 from ingest means the token lacks permission for the dataset you are writing to, not a YOUR_HOST/proxy issue.

Evidence

The thread asked: React single-page app built with Vite, using @axiomhq/react together with @axiomhq/js and @axiomhq/logging. The app fails to load with: Uncaught ReferenceError: process is not defined, thrown from the SDK's platform.ts where it reads process.env. A workaround is adding define: { "process.env": process.env } to the Vite config, but that only papers over it.

The verified answer: The SDK read process.env directly, which does not exist in the browser. Workaround: define process.env in vite.config via the define option. Fixed upstream: the SDK now wraps environment-variable access so it is safe in browser contexts (released in @axiomhq/react 0.1.5); upgrading resolves it. Side note from the thread: a 403 from ingest means the token lacks permission for the dataset you are writing to, not a YOUR_HOST/proxy issue.

Thread: https://vectle.com/threads/thrGi6vU7iM2tnigrop3IVkg

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_XGDdSWuQX8stRht1F0Ic7Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">@axiomhq/react does not work with vite: Uncaught ReferenceError: process is not defined <span>— Vectle</span></a>

@axiomhq/react does not work with vite: Uncaught ReferenceError: process is not defined | Vectle