diff --git a/.changeset/few-experts-prove.md b/.changeset/few-experts-prove.md
new file mode 100644
index 0000000000..543c06ce93
--- /dev/null
+++ b/.changeset/few-experts-prove.md
@@ -0,0 +1,5 @@
+---
+"react-email": patch
+---
+
+Fix missing Request and Response globals
diff --git a/packages/react-email/src/cli/utils/preview/start-dev-server.ts b/packages/react-email/src/cli/utils/preview/start-dev-server.ts
index c307205112..a8a37ae731 100644
--- a/packages/react-email/src/cli/utils/preview/start-dev-server.ts
+++ b/packages/react-email/src/cli/utils/preview/start-dev-server.ts
@@ -120,7 +120,7 @@ export const startDevServer = async (
// this is the most reliable way of communicating these paths through
process.env = {
...process.env,
- NODE_ENV: "development",
+ NODE_ENV: 'development',
...getEnvVariablesForPreviewApp(
// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
path.normalize(emailsDirRelativePath),
diff --git a/packages/react-email/src/utils/__snapshots__/get-email-component.spec.ts.snap b/packages/react-email/src/utils/__snapshots__/get-email-component.spec.ts.snap
index e0f4f5e89a..aede52a8c8 100644
--- a/packages/react-email/src/utils/__snapshots__/get-email-component.spec.ts.snap
+++ b/packages/react-email/src/utils/__snapshots__/get-email-component.spec.ts.snap
@@ -1,3 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
-exports[`getEmailComponent() with a demo email template 1`] = `"
Join Alan on Vercel
Join Enigma on Vercel Hello alanturing,
Alan (alan.turing@example.com ) has invited you to the Enigma team on Vercel .
or copy and paste this URL into your browser: https://vercel.com/teams/invite/foo
This invitation was intended for alanturing . This invite was sent from 204.13.186.218 located in São Paulo, Brazil . If you were not expecting this invitation, you can ignore this email. If you are concerned about your account's safety, please reply to this email to get in touch with us.
"`;
+exports[`getEmailComponent() > with a demo email template 1`] = `"Join Alan on Vercel
Join Enigma on Vercel Hello alanturing,
Alan (alan.turing@example.com ) has invited you to the Enigma team on Vercel .
or copy and paste this URL into your browser: https://vercel.com/teams/invite/foo
This invitation was intended for alanturing . This invite was sent from 204.13.186.218 located in São Paulo, Brazil . If you were not expecting this invitation, you can ignore this email. If you are concerned about your account's safety, please reply to this email to get in touch with us.
"`;
diff --git a/packages/react-email/src/utils/get-email-component.spec.ts b/packages/react-email/src/utils/get-email-component.spec.ts
index 3378f61df1..0d23d75997 100644
--- a/packages/react-email/src/utils/get-email-component.spec.ts
+++ b/packages/react-email/src/utils/get-email-component.spec.ts
@@ -1,27 +1,41 @@
import path from 'node:path';
import { getEmailComponent } from './get-email-component';
-test('getEmailComponent() with a demo email template', async () => {
- const result = await getEmailComponent(
- path.resolve(
- __dirname,
- '../../../../apps/demo/emails/notifications/vercel-invite-user.tsx',
- ),
- );
+describe('getEmailComponent()', () => {
+ describe('Node internals support', () => {
+ test('Request', async () => {
+ const result = await getEmailComponent(
+ path.resolve(__dirname, './testing/request-response-email.tsx'),
+ );
+ if ('error' in result) {
+ console.log(result.error);
+ expect('error' in result, 'there should be no errors').toBe(false);
+ }
+ });
+ });
- if ('error' in result) {
- console.log(result.error);
- expect('error' in result).toBe(false);
- } else {
- expect(result.emailComponent).toBeTruthy();
- expect(result.sourceMapToOriginalFile).toBeTruthy();
-
- const emailHtml = await result.render(
- result.createElement(
- result.emailComponent,
- result.emailComponent.PreviewProps,
+ test('with a demo email template', async () => {
+ const result = await getEmailComponent(
+ path.resolve(
+ __dirname,
+ '../../../../apps/demo/emails/notifications/vercel-invite-user.tsx',
),
);
- expect(emailHtml).toMatchSnapshot();
- }
+
+ if ('error' in result) {
+ console.log(result.error);
+ expect('error' in result).toBe(false);
+ } else {
+ expect(result.emailComponent).toBeTruthy();
+ expect(result.sourceMapToOriginalFile).toBeTruthy();
+
+ const emailHtml = await result.render(
+ result.createElement(
+ result.emailComponent,
+ result.emailComponent.PreviewProps,
+ ),
+ );
+ expect(emailHtml).toMatchSnapshot();
+ }
+ });
});
diff --git a/packages/react-email/src/utils/get-email-component.ts b/packages/react-email/src/utils/get-email-component.ts
index eba33e4ff1..c3496c95bd 100644
--- a/packages/react-email/src/utils/get-email-component.ts
+++ b/packages/react-email/src/utils/get-email-component.ts
@@ -66,6 +66,8 @@ export const getEmailComponent = async (
console,
Buffer,
TextDecoder,
+ Request,
+ Response,
TextDecoderStream,
TextEncoder,
TextEncoderStream,
diff --git a/packages/react-email/src/utils/testing/request-response-email.tsx b/packages/react-email/src/utils/testing/request-response-email.tsx
new file mode 100644
index 0000000000..0272314717
--- /dev/null
+++ b/packages/react-email/src/utils/testing/request-response-email.tsx
@@ -0,0 +1,9 @@
+/* eslint-disable @typescript-eslint/no-unused-vars */
+const req = new Request('https://react.email');
+const res = new Response('{}');
+
+const Email = () => {
+ return
;
+};
+
+export default Email;