resend / resend-node

Resend's Official Node.js SDK
MIT License
512 stars 39 forks source link

`process` is not defined error for Vite and Workers #237

Closed mfaeezshabbir closed 7 months ago

mfaeezshabbir commented 9 months ago

Problem: My challenge arises from the development environment I am using – Vite with React. Vite doesn't enable the direct use of process.env, which is typically how environment variables are accessed. Instead, it relies on import.meta.env for environment variables.

Error: While trying to integrate Resend into my Vite React project, I encountered a critical issue. It seems that Resend's dependency files internally use process, which is not recognized within Vite, leading to a "Process is not defined" error. This error effectively blocks the usage of Resend within a Vite project, and as a result, the straightforward integration process becomes problematic.

Request: I would like to propose an enhancement or modification to the Resend library to ensure its compatibility with Vite React. Specifically, I suggest replacing the usage of process with import.meta.env or making the library Vite-friendly in a way that allows developers to use it seamlessly within Vite projects.

Expected Outcome: The desired outcome is a Resend library that seamlessly integrates with Vite React projects, removing the "Process is not defined" error and making email sending via Resend as straightforward as intended.

Error Image

mikessdev commented 9 months ago

I'm seeing the same error as well with vite + vuejs3.

mfaeezshabbir commented 9 months ago

I'm seeing the same error as well with vite + vuejs3.

Found any solution?

A-believer commented 8 months ago

I am also having the same problem. Please share solutions

zenorocha commented 8 months ago

We've been seeing other users having the same issue in other serverless platforms, including Cloudflare Workers.

It seems that the nodejs resend module uses process.env. This maybe yields the error "ReferenceError: process is not defined" when I deploy to cloudflare pages. Not 100% sure but likely.

And Qwik:

I'm using "resend": "^1.0.0" in my Qwik project. I'm deployed on Edge where the Node API process instance is no defined. My error is:

ReferenceError: process is not defined
   at node_modules/resend/build/src/resend.js

in this line specifically:

    var baseUrl = process.env.RESEND_BASE_URL || "https://api.resend.com";

Would appreciate your assistance here. Thanks.

bukinoshita commented 7 months ago

Can one share an example on how to reproduce this issue? A minimal repository would be helpful if possible 🙏

mikessdev commented 7 months ago

Can one share an example on how to reproduce this issue? A minimal repository would be helpful if possible 🙏

I created a small example of how this error was occurring in my project with vuejs3 + viter:

https://github.com/mikessdev/resendViteEnvError

I hope it can be useful.

zenorocha commented 7 months ago

This has been fixed on v2.1.0.