Skip to content

TypeError: Cannot read properties of undefined (reading 'prototype') when using Next.js 16 + Turbopack #1152

@YaronRosh

Description

@YaronRosh

Description

I am encountering a TypeError immediately upon starting my Next.js application when twilio is imported. This issue appears to be related to how the library is bundled by Turbopack (Next.js bundler) in a dev environment.

The error disappears if I add twilio to serverExternalPackages in next.config.mjs, forcing it to be excluded from the bundle.

Steps to Reproduce

  1. Initialize a Next.js 16 project.
  2. Install twilio.
  3. Import twilio in a server-side file (e.g., a service or API route).
  4. Run the dev server with Turbopack: next dev --turbo.

Code Snippet

import twilio from 'twilio';

// The error happens immediately on import, before any code runs.
const client = twilio(accountSid, authToken);### Exception/Log

Exception/Log

TypeError: Cannot read properties of undefined (reading 'prototype')
   at <unknown> (src/server/services/chat/providers/twilio/twilio.provider.ts:1:1)
   at module evaluation (.next/dev/server/chunks/src_server_services_....js:1847:30)
> 1 | import tw*   **Twilio:** v5.10.6
  • OS: macOS Darwin 25.1.0 (arm64)
  • Bundler: Turbopack (--turbo)

Workaround

Adding twilio to serverExternalPackages in next.config.mjs solves the issue:

// next.config.mjs
const config = {
  serverExternalPackages: ['twilio'],
  // ...
};

Environment

  • Node.js: v20.19.5
  • Next.js: v16.0.1
  • Twilio: v5.10.6
  • OS: macOS Darwin 25.1.0 (arm64)
  • Bundler: Turbopack (--turbo)

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