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

process is not defined error for Vite and Workers #237

Closed
mfaeezshabbir opened this issue Oct 14, 2023 · 7 comments · Fixed by #281
Closed

process is not defined error for Vite and Workers #237

mfaeezshabbir opened this issue Oct 14, 2023 · 7 comments · Fixed by #281

Comments

@mfaeezshabbir
Copy link

mfaeezshabbir commented Oct 14, 2023

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
Copy link

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

@mfaeezshabbir
Copy link
Author

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

Found any solution?

@A-believer
Copy link

I am also having the same problem.
Please share solutions

@zenorocha
Copy link
Contributor

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
Copy link
Member

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

@mikessdev
Copy link

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.

@bukinoshita bukinoshita changed the title Resend Integration with Vite React: Addressing "Process" Error process is not defined error for Vite and Workers Dec 21, 2023
@zenorocha
Copy link
Contributor

This has been fixed on v2.1.0.

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

Successfully merging a pull request may close this issue.

5 participants