Skip to content

Commit fae09e7

Browse files
Copilothotlong
andauthored
fix(studio): export webcrypto from node-polyfills to fix build
The studio Vite build aliases 'crypto' to mocks/node-polyfills.ts. @objectstack/runtime imports `webcrypto` from 'crypto', so the polyfill must export it. Map webcrypto to globalThis.crypto (Web Crypto API) which provides the same SubtleCrypto/getRandomValues surface in browsers. Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/49abf5ad-ca45-4ce6-b799-657ad8f2cd69 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent cb3b6f1 commit fae09e7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

apps/studio/mocks/node-polyfills.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,13 @@ export const rename = async () => {};
102102
export const renameSync = () => {};
103103
export const createHash = () => ({ update: () => ({ digest: () => '' }) });
104104
export const randomUUID = () => '00000000-0000-0000-0000-000000000000';
105+
106+
// node:crypto webcrypto polyfill — maps to the browser's native Web Crypto API.
107+
// The runtime package uses `import { webcrypto as crypto } from "crypto"` to access
108+
// SubtleCrypto/getRandomValues; in the browser, globalThis.crypto provides the same surface.
109+
export const webcrypto =
110+
(typeof globalThis !== 'undefined' && (globalThis as any).crypto) || {
111+
subtle: undefined,
112+
getRandomValues: <T extends ArrayBufferView | null>(array: T): T => array,
113+
randomUUID: () => '00000000-0000-0000-0000-000000000000',
114+
};

0 commit comments

Comments
 (0)