**fix(cli): patch TextEncoder for Node.js v24 compatibility**

- Added a fallback mechanism to ensure `TextEncoder` and `TextDecoder` are available in the `util` module for Node.js v24.
- This fix resolves compatibility issues with TensorFlow.js in Node.js v24 environments.
- Synchronized CLI package version to `0.9.21` and updated `@soulcraft/brainy` dependency reference in `package-lock.json`.

This update ensures smoother functionality in Node.js v24 while maintaining version alignment across dependencies.
This commit is contained in:
David Snelling 2025-07-02 12:38:42 -07:00
parent 30e0652c0c
commit 1d3ac8b7d2
2 changed files with 21 additions and 6 deletions

View file

@ -1,16 +1,16 @@
{
"name": "@soulcraft/brainy-cli",
"version": "0.9.20",
"version": "0.9.21",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@soulcraft/brainy-cli",
"version": "0.9.20",
"version": "0.9.21",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {
"@soulcraft/brainy": "0.9.20",
"@soulcraft/brainy": "0.9.21",
"commander": "^14.0.0",
"omelette": "^0.4.17"
},
@ -2086,9 +2086,9 @@
}
},
"node_modules/@soulcraft/brainy": {
"version": "0.9.20",
"resolved": "https://registry.npmjs.org/@soulcraft/brainy/-/brainy-0.9.20.tgz",
"integrity": "sha512-u+3/xueXfaFMYrckdxeSrjIA5jMEkEcQr/0BUFS3hDjYMHu5MtP7lUXxyVjmNf8RI72L+m2PMIbmxQ5qXG+8Zw==",
"version": "0.9.21",
"resolved": "https://registry.npmjs.org/@soulcraft/brainy/-/brainy-0.9.21.tgz",
"integrity": "sha512-UimglEpucGsiRXZlsSx4jZis0cIGKAxPU7lk/m6LvygRm01r9NPTCpsrT3mp38JMbEkzm4JpmP8vHaC5hWzXZQ==",
"hasInstallScript": true,
"license": "MIT",
"dependencies": {

View file

@ -12,6 +12,21 @@ import { fileURLToPath } from 'url'
import { dirname, join } from 'path'
import fs from 'fs'
// Fix for TextEncoder in Node.js v24
// In Node.js v24, TextEncoder is a global object and not part of the util module
// This patch ensures that the util module has TextEncoder available for TensorFlow.js
if (process.versions.node.startsWith('24')) {
try {
const util = await import('util')
if (!util.TextEncoder && typeof TextEncoder !== 'undefined') {
util.TextEncoder = TextEncoder
util.TextDecoder = TextDecoder
}
} catch (error) {
console.warn('Warning: Failed to patch TextEncoder for Node.js v24:', error.message)
}
}
// Get the directory of the current module
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)