-
Notifications
You must be signed in to change notification settings - Fork 547
Open
Description
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
- Initialize a Next.js 16 project.
- Install
twilio. - Import
twilioin a server-side file (e.g., a service or API route). - 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)
AlonMizAlonMiz
Metadata
Metadata
Assignees
Labels
No labels