Issue with importing from @google/genai/node
fails in Cloudflare Workers environment
#324
Labels
priority: p2
Moderately-important priority. Fix may not be included in next release.
type: bug
Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Problem
When importing directly from
@google/genai/node
in a Cloudflare Worker, the application fails due to limited Node.js compatibility in the Workers environment.The specific error occurs in the
google-logging-utils
package when checking if colors should be enabled. The function attempts to callstream.getColorDepth()
on the proxiedprocess.stderr
object, resulting in:Investigation
The issue occurs in the
isEnabled
method of theColours
class ingoogleapis/gax-nodejs/logging-utils/src/colours.ts](https://github.com/googleapis/gax-nodejs/blob/main/logging-utils/src/colours.ts#L55)
where it makes this check:Since Cloudflare Workers only provide a polyfilled version of
process.stderr
using aProxy
, this function call fails.Temporary Fix
I've temporarily patched the dependency by adding try/catch error handling:
This patch gracefully handles the error by defaulting to disabled colors when the check fails.
The text was updated successfully, but these errors were encountered: