fix(core): Core loads Node.js-only modules at import time and crashes browser bundles #89

Closed
opened 2026-12-01 14:59:57 +00:00 by crapougnax · 0 comments
Owner

Problem

@quatrain/core imports node-persist, node:child_process and which at module load (packages/core/src/Core.ts).

Since @quatrain/http 1.0.6 depends on @quatrain/core (MessagePack normalizer, #82), every browser app using @quatrain/api-client now bundles Core. On load, which → isexe reads process.platform and the app crashes:

ReferenceError: process is not defined

Observed on a Vite-built backoffice (blank page).

Expected

Core must be importable in a browser. Node.js-only features (Core.storage, execPromise, getSystemCommandPath) may fail when used there, but not at import time.

Fix

Load these modules lazily on first use, with a regression test asserting none of them is evaluated when importing Core.

Follow-up (out of scope)

properties/HashProperty.ts imports node:crypto at top level: Vite stubs it (fails on use), stricter bundlers (bun build --target=browser) refuse to build. Candidate for lazy loading or Web Crypto.

## Problem `@quatrain/core` imports `node-persist`, `node:child_process` and `which` at module load (`packages/core/src/Core.ts`). Since `@quatrain/http` 1.0.6 depends on `@quatrain/core` (MessagePack normalizer, #82), every browser app using `@quatrain/api-client` now bundles Core. On load, `which` → `isexe` reads `process.platform` and the app crashes: ``` ReferenceError: process is not defined ``` Observed on a Vite-built backoffice (blank page). ## Expected Core must be importable in a browser. Node.js-only features (`Core.storage`, `execPromise`, `getSystemCommandPath`) may fail when *used* there, but not at import time. ## Fix Load these modules lazily on first use, with a regression test asserting none of them is evaluated when importing Core. ## Follow-up (out of scope) `properties/HashProperty.ts` imports `node:crypto` at top level: Vite stubs it (fails on use), stricter bundlers (`bun build --target=browser`) refuse to build. Candidate for lazy loading or Web Crypto.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quatrain/core#89
No description provided.