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

Getting error "Headers is not defined" when calling Resend constructor (not backwards compatible from Node 18) #10

Open
jbexx opened this issue Nov 6, 2023 · 3 comments

Comments

@jbexx
Copy link

jbexx commented Nov 6, 2023

Im trying to setup Resend in an express project that is on Node version 17

Im on the latest version of Resend v2.0.0

When running the project I get an error saying:

"ReferenceError: Headers is not defined",
" at new Resend (/var/task/node_modules/resend/build/src/resend.js:34:28)",

The line referenced begins here:
... this.headers = new Headers({ Authorization: Bearer ${this.key}, 'User-Agent': userAgent, 'Content-Type': 'application/json', }); ...

where you're using the Headers interface of the fetch API. Unfortunately this is only supported in Node version 18 and greater. I don't think I saw anything in your documentation while getting setup that Node version 18 was a requirement. Will you ever offer some sort of backward compatibility?

When I clone this resend-express-example project I don't see this error, but it looks like the Resend version that gets downloaded is version 0.17.1 where the Headers interface isn't being used. What version was this implemented? Is it recommended that I roll back instead of waiting for support in the latest version?

@joao00paixao
Copy link

Have you found a fix for this?

@jbexx
Copy link
Author

jbexx commented Feb 11, 2024

I ended up just bumping my project node version to 18. If you need this to work and you aren't able to update your node version for some reason you could just roll back to an earlier version of resend (not sure what version this was implemented but you could find out digging through the commit history) or submit an MR that replaces the Headers interface so it's more backward compatible.

@joao00paixao
Copy link

Unfortunately I was locked to Azure's Node 16 but I switched into a container environment and it's all good now. I didn't try downgrading the package though. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants