**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:
parent
30e0652c0c
commit
1d3ac8b7d2
2 changed files with 21 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue