-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Closed
Labels
Description
Link to the code that reproduces this issue
https://github.com/kyeb/sendgrid-turbopack-bug
To Reproduce
- Clone the repository:
git clone https://github.com/kyeb/sendgrid-turbopack-bug
- Install dependencies:
npm install
- Start with Turbopack:
npm run dev
- Test the server action:
curl http://localhost:3000/api/test
- Observe the error in the response and server console
Current vs. Expected behavior
Current behavior:
When calling @sendgrid/mail.setApiKey()
from a Server Action with Turbopack enabled, it throws:
TypeError: Cannot read properties of undefined (reading 'client')
at testSendGrid (app/action.ts:8:21)
Expected behavior:
setApiKey()
should work consistently across all bundlers. The same code works fine when using webpack bundler (npm run dev:webpack
).
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.5.0
Binaries:
Node: 22.14.0
npm: 11.4.1
Relevant Packages:
next: 15.4.0-canary.84
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
@sendgrid/mail: 8.1.5
Which area(s) are affected? (Select all that apply)
Turbopack (--turbo)
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
This issue only occurs when all three conditions are met:
- Next.js canary with Turbopack enabled (
--turbo
) - Server Actions (
'use server'
) - SendGrid's
setApiKey()
method
The same code works fine in Server Actions with webpack bundler, suggesting this is a Turbopack-specific issue with how it handles the SendGrid module's internal state or initialization.