Skip to content

Bug: SendGrid setApiKey() fails in Server Actions with Turbopack #80637

@kyeb

Description

@kyeb

Link to the code that reproduces this issue

https://github.com/kyeb/sendgrid-turbopack-bug

To Reproduce

  1. Clone the repository: git clone https://github.com/kyeb/sendgrid-turbopack-bug
  2. Install dependencies: npm install
  3. Start with Turbopack: npm run dev
  4. Test the server action: curl http://localhost:3000/api/test
  5. 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:

  1. Next.js canary with Turbopack enabled (--turbo)
  2. Server Actions ('use server')
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurbopackRelated to Turbopack with Next.js.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions