Skip to content

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

@lihuimingxs

Description

@lihuimingxs

Before submitting an issue, please:

Environment Information

Stagehand:

  • Language/SDK: TypeScript
  • Stagehand version: 3.0.6

AI Provider:

  • Provider: Browserbase
  • Model: N/A (issue occurs during initialization)

Runtime Environment:

  • Framework: Next.js 14+ (App Router / Pages Router)
  • Node.js: 20.x
  • Deployment: Vercel / Railway

Issue Description

When using @browserbasehq/stagehand in Next.js projects, all Stagehand operations fail with the following error:

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

Root Cause

The pino-pretty dependency is currently declared as a regular dependency. In Next.js and serverless environments, pino-pretty relies on Node.js worker threads which may not be available or properly initialized at runtime, causing failures when pino attempts to load it as a transport target.

Affected Environments

  • ✅ Next.js (App Router / Pages Router)
  • ✅ Remix, SvelteKit, and other modern bundler-based frameworks
  • ✅ Serverless environments (Vercel, Netlify, AWS Lambda)
  • ❌ Pure Node.js environments (unaffected)

Steps to Reproduce

  1. Create a Next.js 14+ project
  2. Install @browserbasehq/stagehand@3.0.6
  3. Initialize Stagehand in an API Route or Server Component
  4. Run or build the application

Minimal Reproduction Code

// app/api/test/route.ts (Next.js 14 App Router)
import { Stagehand } from "@browserbasehq/stagehand";

export async function GET() {
  const stagehand = new Stagehand({
    env: "BROWSERBASE",
    apiKey: process.env.BROWSERBASE_API_KEY,
    projectId: process.env.BROWSERBASE_PROJECT_ID,
    verbose: 1,
  });

  try {
    await stagehand.init(); // ❌ Fails here
    const page = stagehand.context.pages()[0];
    await page.goto("https://example.com");
    
    return Response.json({ success: true });
  } catch (error) {
    console.error(error);
    return Response.json({ error: String(error) }, { status: 500 });
  }
}

Error Messages / Log trace

Navigation failed: Error: unable to determine transport target for "pino-pretty"
    at p1 (.next/server/chunks/[root-of-the-server]__9b8e2a0d._.js:5:324)
    at Object.execute (.next/server/chunks/[root-of-the-server]__9b8e2a0d._.js:10:214)

Current Workaround

Users can bypass this issue by setting disablePino: true:

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  projectId: process.env.BROWSERBASE_PROJECT_ID,
  verbose: 1,
  disablePino: true, // ⭐ Workaround
});

However, this requires manual configuration for each project.

Screenshots / Videos

N/A


Additional Context

I noticed that:

  1. The code already has fallback logic when pino-pretty is unavailable (lib/logger.ts:49-52)
  2. All test configurations use disablePino: true
  3. pino-pretty is currently in dependencies, which causes bundlers to include it even in production builds
  4. According to Pino's documentation, pino-pretty is designed for development environments only

I'm wondering if moving pino-pretty to optionalDependencies would help, but I'm concerned about the verbose parameter defaulting to 1 and pretty: true in the code. I'm not sure how this would affect the default behavior. Any guidance would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions