Skip to content

fix: move pino-pretty to optionalDependencies and fix fallback in serverless envs#2034

Open
octo-patch wants to merge 1 commit intobrowserbase:mainfrom
octo-patch:fix/issue-1464-pino-pretty-optional
Open

fix: move pino-pretty to optionalDependencies and fix fallback in serverless envs#2034
octo-patch wants to merge 1 commit intobrowserbase:mainfrom
octo-patch:fix/issue-1464-pino-pretty-optional

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

@octo-patch octo-patch commented Apr 24, 2026

Fixes #1464

Problem

pino-pretty was declared as a regular dependency, 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:

Error: unable to determine transport target for "pino-pretty"

Additionally, the existing fallback in createLogger was broken: the try/catch block only wrapped Object.assign(loggerConfig, transport), which never throws — the actual error comes from the pino() call that follows, outside the try block.

Solution

  1. Move pino-pretty to optionalDependencies — bundlers can now exclude it when not needed, and package managers will skip it when it cannot be installed (e.g. restricted environments).

  2. Fix the try/catch scope in createLogger — the pino() 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 existing disablePino: true workaround continues to work as before.

Testing

  • Existing behaviour: in standard Node.js environments with pino-pretty available, pretty-printed logs still work.
  • In environments where pino-pretty is excluded or worker threads are unavailable, stagehand now initialises successfully and logs in plain JSON format instead of throwing.
  • The disablePino: true option remains as an explicit opt-out.

Summary by cubic

Make pino-pretty optional and fix the logger fallback so serverless builds don’t crash. If pino-pretty isn’t available or worker threads are blocked, we now fall back to plain JSON logging.

  • Dependencies

    • Moved pino-pretty to optionalDependencies so bundlers can exclude it.
    • Allows installs to skip pino-pretty in restricted environments.
  • Bug Fixes

    • Wrapped the pino() call with the pretty transport in a try/catch; on failure, log a warning and use JSON output.
    • No change when pino-pretty is available; disablePino: true still works.

Written for commit 2d4d25d. Summary will update on new commits. Review in cubic

…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>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 2d4d25d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Apr 24, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Suggest] Move pino-pretty to optionalDependencies for Next.js/Serverless compatibility

1 participant