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:
- Clone the reproduction repo: https://github.com/EpicPlayerA10/nextjs-send-emails-wrangler-bug
- Run
pnpm run dev
- Open website
localhost:3000
- Click on
Send Email button
- 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)
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_emailbinding and when I try to use it innext devthen it doesn't work at all. Here is an error:Steps to reproduce the error:
pnpm run devlocalhost:3000Send EmailbuttonAlthough when you run
pnpm run previewthis 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
workers-sdk/packages/miniflare/src/plugins/email/index.ts
Lines 71 to 73 in fc2d883
getNodeBindingsreturns an empty object. But when I replaced it to return bindings withProxyNodeBindingand when I tried to send an email then the website would hang indefinitely.Please provide any relevant error logs