fix: resolve browser compatibility by avoiding Node.js process access in nodeVersionCheck
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
a439772aa6
commit
baf80b5f24
1 changed files with 31 additions and 8 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* Node.js Version Compatibility Check
|
* Node.js Version Compatibility Check
|
||||||
*
|
*
|
||||||
* Brainy requires Node.js 22.x LTS for maximum stability with ONNX Runtime.
|
* Brainy requires Node.js 22.x LTS for maximum stability with ONNX Runtime.
|
||||||
* This prevents V8 HandleScope locking issues in worker threads.
|
* This prevents V8 HandleScope locking issues in worker threads.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { isNode } from './environment.js'
|
||||||
|
|
||||||
export interface VersionInfo {
|
export interface VersionInfo {
|
||||||
current: string
|
current: string
|
||||||
major: number
|
major: number
|
||||||
|
|
@ -16,16 +18,27 @@ export interface VersionInfo {
|
||||||
* Check if the current Node.js version is supported
|
* Check if the current Node.js version is supported
|
||||||
*/
|
*/
|
||||||
export function checkNodeVersion(): VersionInfo {
|
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 nodeVersion = process.version
|
||||||
const majorVersion = parseInt(nodeVersion.split('.')[0].substring(1))
|
const majorVersion = parseInt(nodeVersion.split('.')[0].substring(1))
|
||||||
|
|
||||||
const versionInfo: VersionInfo = {
|
const versionInfo: VersionInfo = {
|
||||||
current: nodeVersion,
|
current: nodeVersion,
|
||||||
major: majorVersion,
|
major: majorVersion,
|
||||||
isSupported: majorVersion === 22,
|
isSupported: majorVersion === 22,
|
||||||
recommendation: 'Node.js 22.x LTS'
|
recommendation: 'Node.js 22.x LTS'
|
||||||
}
|
}
|
||||||
|
|
||||||
return versionInfo
|
return versionInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +47,12 @@ export function checkNodeVersion(): VersionInfo {
|
||||||
*/
|
*/
|
||||||
export function enforceNodeVersion(): void {
|
export function enforceNodeVersion(): void {
|
||||||
const versionInfo = checkNodeVersion()
|
const versionInfo = checkNodeVersion()
|
||||||
|
|
||||||
|
// Skip enforcement in browser environment
|
||||||
|
if (!isNode()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (!versionInfo.isSupported) {
|
if (!versionInfo.isSupported) {
|
||||||
const errorMessage = [
|
const errorMessage = [
|
||||||
'🚨 BRAINY COMPATIBILITY ERROR',
|
'🚨 BRAINY COMPATIBILITY ERROR',
|
||||||
|
|
@ -54,7 +72,7 @@ export function enforceNodeVersion(): void {
|
||||||
'🔗 More info: https://github.com/soulcraftlabs/brainy#node-version',
|
'🔗 More info: https://github.com/soulcraftlabs/brainy#node-version',
|
||||||
'━'.repeat(50)
|
'━'.repeat(50)
|
||||||
].join('\n')
|
].join('\n')
|
||||||
|
|
||||||
throw new Error(errorMessage)
|
throw new Error(errorMessage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +82,12 @@ export function enforceNodeVersion(): void {
|
||||||
*/
|
*/
|
||||||
export function warnNodeVersion(): boolean {
|
export function warnNodeVersion(): boolean {
|
||||||
const versionInfo = checkNodeVersion()
|
const versionInfo = checkNodeVersion()
|
||||||
|
|
||||||
|
// Skip warning in browser environment
|
||||||
|
if (!isNode()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if (!versionInfo.isSupported) {
|
if (!versionInfo.isSupported) {
|
||||||
console.warn([
|
console.warn([
|
||||||
'⚠️ BRAINY VERSION WARNING',
|
'⚠️ BRAINY VERSION WARNING',
|
||||||
|
|
@ -73,9 +96,9 @@ export function warnNodeVersion(): boolean {
|
||||||
' Consider upgrading for best stability',
|
' Consider upgrading for best stability',
|
||||||
''
|
''
|
||||||
].join('\n'))
|
].join('\n'))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue