From baf80b5f24b94f48f7af98ea46c8bc7e20300364 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Wed, 17 Sep 2025 16:59:59 -0700 Subject: [PATCH] fix: resolve browser compatibility by avoiding Node.js process access in nodeVersionCheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add environment detection using isNode() check - Skip Node.js version validation in browser environments - Return browser-friendly defaults when not in Node.js - Prevents "Cannot read properties of undefined (reading 'isTTY')" error - Ensures external bundlers (Vite, Webpack) work correctly with Brainy 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/utils/nodeVersionCheck.ts | 39 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/utils/nodeVersionCheck.ts b/src/utils/nodeVersionCheck.ts index 5fa996b2..d73a9061 100644 --- a/src/utils/nodeVersionCheck.ts +++ b/src/utils/nodeVersionCheck.ts @@ -1,10 +1,12 @@ /** * Node.js Version Compatibility Check - * + * * Brainy requires Node.js 22.x LTS for maximum stability with ONNX Runtime. * This prevents V8 HandleScope locking issues in worker threads. */ +import { isNode } from './environment.js' + export interface VersionInfo { current: string major: number @@ -16,16 +18,27 @@ export interface VersionInfo { * Check if the current Node.js version is supported */ export function checkNodeVersion(): VersionInfo { + // In browser environment, skip version check + if (!isNode()) { + return { + current: 'browser', + major: 0, + isSupported: true, // Always supported in browser + recommendation: 'Browser environment' + } + } + + // Only access process.version in Node.js environment const nodeVersion = process.version const majorVersion = parseInt(nodeVersion.split('.')[0].substring(1)) - + const versionInfo: VersionInfo = { current: nodeVersion, major: majorVersion, isSupported: majorVersion === 22, recommendation: 'Node.js 22.x LTS' } - + return versionInfo } @@ -34,7 +47,12 @@ export function checkNodeVersion(): VersionInfo { */ export function enforceNodeVersion(): void { const versionInfo = checkNodeVersion() - + + // Skip enforcement in browser environment + if (!isNode()) { + return + } + if (!versionInfo.isSupported) { const errorMessage = [ '🚨 BRAINY COMPATIBILITY ERROR', @@ -54,7 +72,7 @@ export function enforceNodeVersion(): void { '🔗 More info: https://github.com/soulcraftlabs/brainy#node-version', '━'.repeat(50) ].join('\n') - + throw new Error(errorMessage) } } @@ -64,7 +82,12 @@ export function enforceNodeVersion(): void { */ export function warnNodeVersion(): boolean { const versionInfo = checkNodeVersion() - + + // Skip warning in browser environment + if (!isNode()) { + return true + } + if (!versionInfo.isSupported) { console.warn([ '⚠️ BRAINY VERSION WARNING', @@ -73,9 +96,9 @@ export function warnNodeVersion(): boolean { ' Consider upgrading for best stability', '' ].join('\n')) - + return false } - + return true } \ No newline at end of file