Skip to content

Can't use send_email binding when in local development using proxy bindings #13715

@EpicPlayerA10

Description

@EpicPlayerA10

What versions & operating system are you using?

System:
OS: Windows 11 10.0.22631
CPU: (16) x64 Intel(R) Core(TM) i9-9900KF CPU @ 3.60GHz
Memory: 4.80 GB / 31.94 GB
Binaries:
Node: 22.17.1 - C:\Program Files\nodejs\node.EXE
npm: 9.8.1 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.27.0 - C:\Users\xxx\AppData\Roaming\npm\pnpm.CMD
npmPackages:
wrangler: ^4.85.0 => 4.85.0

Please provide a link to a minimal reproduction

https://github.com/EpicPlayerA10/nextjs-send-emails-wrangler-bug

Describe the Bug

In next.js using OpenNext when I add a send_email binding and when I try to use it in next dev then it doesn't work at all. Here is an error:

 POST / 500 in 291ms (next.js: 3ms, application-code: 288ms)
  └─ ƒ sendEmail() in 1ms src/app/actions.ts
[browser] Error sending email: TypeError: Cannot read properties of undefined (reading 'send')
    at sendEmail (src\app\actions.ts:9:28)
   7 |
   8 |     console.log("Sending email...");
>  9 |     await env.EMAIL_SENDER.send({
     |                            ^
  10 |         from: "sender@example.com",
  11 |         to: "receiver@example.com",
  12 |         subject: "Hello from Cloudflare Workers!", (src/app/page.tsx:17:12)

Steps to reproduce the error:

  1. Clone the reproduction repo: https://github.com/EpicPlayerA10/nextjs-send-emails-wrangler-bug
  2. Run pnpm run dev
  3. Open website localhost:3000
  4. Click on Send Email button
  5. See that it throws an error in console that binding does not exist

Although when you run pnpm run preview this binding works perfectly fine. But this requires you to build next.js app every time when you want to test it.

Also I was digging a bit more into this issue and I discovered that the root cause is that

getNodeBindings(_options) {
return {};
},
getNodeBindings returns an empty object. But when I replaced it to return bindings with ProxyNodeBinding and when I tried to send an email then the website would hang indefinitely.

Please provide any relevant error logs

 POST / 500 in 291ms (next.js: 3ms, application-code: 288ms)
  └─ ƒ sendEmail() in 1ms src/app/actions.ts
[browser] Error sending email: TypeError: Cannot read properties of undefined (reading 'send')
    at sendEmail (src\app\actions.ts:9:28)
   7 |
   8 |     console.log("Sending email...");
>  9 |     await env.EMAIL_SENDER.send({
     |                            ^
  10 |         from: "sender@example.com",
  11 |         to: "receiver@example.com",
  12 |         subject: "Hello from Cloudflare Workers!", (src/app/page.tsx:17:12)

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions