fix: move pino-pretty to optionalDependencies and fix fallback in serverless envs#2034
fix: move pino-pretty to optionalDependencies and fix fallback in serverless envs#2034octo-patch wants to merge 1 commit intobrowserbase:mainfrom
Conversation
…verless envs pino-pretty was listed as a regular dependency, causing bundlers (Next.js, Vercel, etc.) to include it even in production server builds. Because it relies on Node.js worker threads, it throws "unable to determine transport target for pino-pretty" in environments that restrict worker thread usage. Two changes: 1. Move pino-pretty from dependencies to optionalDependencies so bundlers can exclude it when it is not needed. 2. Fix the try-catch in createLogger: the previous code wrapped only the config object setup (Object.assign), which never throws. The actual pino() call with the transport target is now inside the try block, so failures are caught and pino falls back to plain JSON logging automatically. Fixes browserbase#1464 Co-Authored-By: Octopus <liyuan851277048@icloud.com>
|
|
This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run. |
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant App as Stagehand Client
participant Logger as createLogger()
participant Pino as Pino Library
participant Console as System Console
participant Pretty as pino-pretty (Optional)
App->>Logger: createLogger({ pretty: true })
Note over Logger,Pretty: NEW: Attempt Pretty Logging in Try/Catch
alt Attempt initialization with pino-pretty
Logger->>Pino: CHANGED: Initialize pino({ transport: "pino-pretty" })
Pino->>Pretty: Load transport worker
alt Success (Local/Node.js)
Pretty-->>Pino: Worker started
Pino-->>Logger: Logger instance (Pretty)
Logger-->>App: Return Pretty Logger
else Failure (Serverless / Missing Dependency)
Pino-->>Logger: Throw: "unable to determine transport"
Logger->>Console: NEW: console.warn("falling back to standard logging")
Logger->>Pino: Fallback: Initialize pino() (JSON mode)
Pino-->>Logger: Logger instance (JSON)
Logger-->>App: Return JSON Logger
end
else options.pretty is false OR Test Environment
Logger->>Pino: Initialize pino() (JSON mode)
Pino-->>Logger: Logger instance (JSON)
Logger-->>App: Return JSON Logger
end
Fixes #1464
Problem
pino-prettywas declared as a regulardependency, so bundlers (Next.js, Vercel, Netlify, AWS Lambda, etc.) always include it in production builds. In serverless runtimes that restrict Node.js worker thread usage, pino fails at startup with:Additionally, the existing fallback in
createLoggerwas broken: thetry/catchblock only wrappedObject.assign(loggerConfig, transport), which never throws — the actual error comes from thepino()call that follows, outside the try block.Solution
Move
pino-prettytooptionalDependencies— bundlers can now exclude it when not needed, and package managers will skip it when it cannot be installed (e.g. restricted environments).Fix the
try/catchscope increateLogger— thepino()call with the pretty transport is now inside the try block. If pino fails to initialise the pino-pretty worker thread for any reason, the error is caught and pino falls back to plain JSON logging with a console warning. The existingdisablePino: trueworkaround continues to work as before.Testing
disablePino: trueoption remains as an explicit opt-out.Summary by cubic
Make
pino-prettyoptional and fix the logger fallback so serverless builds don’t crash. Ifpino-prettyisn’t available or worker threads are blocked, we now fall back to plain JSON logging.Dependencies
pino-prettytooptionalDependenciesso bundlers can exclude it.pino-prettyin restricted environments.Bug Fixes
pino()call with the pretty transport in a try/catch; on failure, log a warning and use JSON output.pino-prettyis available;disablePino: truestill works.Written for commit 2d4d25d. Summary will update on new commits. Review in cubic