next.js: TypeError: Cannot read properties of undefined (reading 'current') when adding `--turbo`

Link to the code that reproduces this issue

https://github.com/pjborowiecki/PERSONAL-PORTFOLIO-Next14-Sanity-TypeScript-GSAP-Tailwind

To Reproduce

  1. Fill in the RESEND_API_KEY, RESEND_EMAIL_FROM, and RESEND_EMAIL_TO environment variables in .env file
  2. Start the application without turbo and attempt to use the contact form (works perfectly fine)
  3. Add --turbo to your dev script in package.json, attempt to use the form (and see it logging out the error)

Current vs. Expected behavior

Expecting no errors when submitting a form using Resend and --turbo

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:44 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T8103
Binaries:
  Node: 18.17.0
  npm: 10.2.2
  Yarn: 1.22.19
  pnpm: 8.10.0
Relevant Packages:
  next: 14.0.2-canary.6
  eslint-config-next: 14.0.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack (–turbo)

Additional context

I have been working on my personal portfolio website and set up a contact form with React Hook Form, Resend, and Server Actions.

It works perfectly fine, even after upgrading to Next 14. However, the moment I add --turbo to the dev script, it no longer submits the emails. The action fails with the message: TypeError: cannot read properties of undefined (reading 'current').

The project is completely unstyled yet for larger screens, I am currently working on styling for mobile devices, so please do not get outraged. Styling is irrelevant to the issue.

PACK-2243

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 5
  • Comments: 15 (3 by maintainers)

Commits related to this issue

Most upvoted comments

For what it’s worth, I got the exact same error when using resend with the --turbo flag. Got rid of the flag and everything’s working perfectly

Also ran into this issue with resend and react mail.

However, when using html in the mail headers it works

does not work:

 const data = await resend.emails.send({
      from: "onboarding@resend.dev",
      to: "test@hotmail.com",
      subject: `has a message!`,
      react: NotionMagicLinkEmail({ loginCode: "123456" }),
    })

does work:

const data = await resend.emails.send({
     from: "onboarding@resend.dev",
     to: "test@hotmail.com",
     subject: `has a message!`,
     html: "<p>Hello world!</p>",
   })

Experiencing the same issues with --turbo flag on Next 14.1.0. Both Resend and ZeptoMail result to TypeError: Cannot read properties of undefined (reading ‘current’) however without the --turbo flag everything works fine no errors thrown

@ForsakenHarmony that’s about as minimal as I could get: https://github.com/r4zendev/turbo-repro

If you setup your own Resend configuration and try to send the email, it would fail with an error printed out in the console that is similar to the OP’s. The same works flawlessly with Webpack.

To setup provide a valid resend api key in .env and change the domain from which your email would originate in contact-us.tsx at line 16.

I was able to reproduce when using resend and react-email in server action. Basically, I just created a template, instantiated resend in server action and tried to resend.emails.send. With turbo it errors with the same error as OP described, while with webpack it works well. Let me know if minimal repo for this is still needed.

Ok give me sometime, will try to reproduce this on my end. Will update you in a few hours.