Skip to content

fix: define process in eval sandbox to support CommonJS dev builds#3086

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/process-polyfill-eval-sandbox
Draft

fix: define process in eval sandbox to support CommonJS dev builds#3086
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/process-polyfill-eval-sandbox

Conversation

@posthog

@posthog posthog Bot commented Jul 2, 2026

Copy link
Copy Markdown

Summary

Evaluating any circuit that imports a CommonJS development build (*.development.js) failed with process is not defined in the browser web worker. The eval sandbox in lib/eval/eval-compiled-js.ts injects exports, require, module, and circuit into the evaluated function body but never defined process, so the moment an imported module read process.env.NODE_ENV (which every CJS dev build does) the render threw.

The fix polyfills process in two places:

  • Inject var process = globalThis.process || { env: { NODE_ENV: "production" } } into the eval function body.
  • Add a matching globalThis.process polyfill in webworker/entrypoint.ts, right next to the existing globalThis.global polyfill.

Added a repro test that removes globalThis.process to simulate the worker environment and confirms the sandbox no longer throws.

Why

Users reported hard render failures when importing packages that touch process at module load (e.g. react-reconciler/cjs/react-reconciler-reflection.development.js). This is a correctness gap in the core circuit-evaluation flow affecting a whole class of npm packages, with no obvious workaround.


Created with PostHog Code from an inbox report.

The webworker eval sandbox injected exports/require/module/circuit into the
evaluated function body but never defined `process`. Any imported CommonJS
development build (*.development.js) reads `process.env.NODE_ENV` at module
load, so evaluating such a module threw "process is not defined" and failed
the render.

Inject `var process = globalThis.process || { env: { NODE_ENV: "production" } }`
into the eval function body, and add a matching `globalThis.process` polyfill
in the worker entrypoint next to the existing `globalThis.global` polyfill.

Generated-By: PostHog Code
Task-Id: 3579c101-2794-4a43-80cc-604c74e24dcf
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants