Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'current') when adding --turbo #57936

Closed
1 task done
pjborowiecki opened this issue Nov 2, 2023 · 15 comments · Fixed by #61165
Closed
1 task done
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.

Comments

@pjborowiecki
Copy link

pjborowiecki commented Nov 2, 2023

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

@pjborowiecki pjborowiecki added the bug Issue was opened via the bug report template. label Nov 2, 2023
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Nov 2, 2023
@EliHood
Copy link

EliHood commented Nov 2, 2023

Have you tried to debug the issue, if so, what have you discovered thus far ?

@pjborowiecki
Copy link
Author

pjborowiecki commented Nov 2, 2023

Have you tried to debug the issue, if so, what have you discovered thus far ?

The error message is not very descriptive. It looks something like this:

TypeError: Cannot read properties of undefined (reading 'current')
at `performWork` (/my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:9132:57)
at /my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:9457:28
at `scheduleWork` (/my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:148:13)
at `startWork` (/my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:9456:17)
at `renderToStringImpl` (/my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:9558:13)
at `Module.renderToStaticMarkup` (/my_project/.next/server/chunks/a5f67_next_dist_compiled_react-dom_cjs_react-dom-server-legacy_node_development_1df89d.js:9632:20)
at `render` (/my_project/.next/server/chunks/node_modules__pnpm_fc0103._.js:6700:311)
at `Emails.<anonymous>` (/my_project/.next/server/chunks/node_modules__pnpm_fc0103._.js:7865:52)
at `Generator.next (<anonymous>)`
at /my_project/.next/server/chunks/node_modules__pnpm_fc0103._.js:7845:71
at `new Promise (<anonymous>)`
at module.exports.[project]/node_modules/.pnpm/resend@1.1.0/node_modules/resend/build/src/emails/emails.js [rsc] (ecmascript).__awaiter (my_project/.next/server/chunks/node_modules__pnpm_fc0103._.js:7827:12)
at `Emails.create` (/my_project/.next/server/chunks/node_modules__pnpm_fc0103._.js:7863:16)

.. and so on. --turbo is not crucial for my app to work, so I did not spend too much time debugging it. Just removed the flag for now and everything works fine again.

Mentioned it here for others, and to make Next.js and Resend maintainers aware of this issue. Thank you for the answer

@EliHood
Copy link

EliHood commented Nov 2, 2023

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

@EliHood
Copy link

EliHood commented Nov 2, 2023

@pjborowiecki I think i need some environment variables to reproduce this.

Maybe i just need the projectId ? i added test

I get

body: {
    message: 'Dataset "production" not found for project ID "test"',
    statusCode: 404,
    error: 'Dataset not found'
  },

I think i can add random values for the following, or maybe im wrong.

  • RESEND_API_KEY,
  • RESEND_EMAIL_FROM,
  • RESEND_EMAIL_TO

@padmaia
Copy link
Member

padmaia commented Dec 12, 2023

@pjborowiecki do you have more instructions on how to properly reproduce this issue?

@r4zendev
Copy link

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.

@juancamiloqhz
Copy link

I'm having this exact same issue. I had to move back to Webpack again to be able to develop my app.

@ForsakenHarmony ForsakenHarmony added the linear: turbopack Confirmed issue that is tracked by the Turbopack team. label Jan 16, 2024
@ForsakenHarmony
Copy link
Contributor

Would definitely appreciate a more minimal repro @r4zendev

@r4zendev
Copy link

@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.

@richiemcilroy
Copy link

Getting the same error, in the same place.

@usamaster
Copy link

usamaster commented Jan 21, 2024

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>",
   })

@youngbloodcyb
Copy link

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

@realverse
Copy link

Seeing the same issue. Runs fine without --turbo. But running with --turbo (Next 14.1) causes TypeError: Cannot read properties of undefined (reading 'current').

@gitkenya
Copy link

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 added a commit that referenced this issue Feb 14, 2024
### What?
Probably not the right solution, next.js disables the `react-server`
import condition in there somehow I think

### Why?

Resend uses `@react-email/render` which uses `renderToString` from
`react-dom/server`.
Unfortunately importing `react-dom/server` with the `react-server`
import condition leads to a broken bundle (which seems like a bug in
react?).

Closes PACK-2243
Fixes #57936
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: turbopack Confirmed issue that is tracked by the Turbopack team. locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.