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

Error when instansiating a class with an enviroment variable #325

Closed
6 tasks done
samducker opened this issue Mar 26, 2024 · 2 comments
Closed
6 tasks done

Error when instansiating a class with an enviroment variable #325

samducker opened this issue Mar 26, 2024 · 2 comments

Comments

@samducker
Copy link

Describe the bug

This issue only seems to happen when upgrading to the pre-release version of VSCode which I did to fix another error I was previously having which was recommend by this github repo.

When I am initiating the resend library I am getting the following error.

 FAIL  src/app/api/survey/recruit/tests/recruit.test.ts [ src/app/api/survey/recruit/tests/recruit.test.ts ]
Error: Missing API key. Pass it to the constructor `new Resend("re_123")`
 ❯ new Resend node_modules/resend/dist/index.mjs:325:15
    323|       }
    324|       if (!this.key) {
    325|         throw new Error(
       |               ^
    326|           'Missing API key. Pass it to the constructor `new Resend("re_123")`'
    327|         );

My implementation

import { beforeEach, expect, test } from "vitest";
import { loadEnvConfig } from "@next/env";
import { Resend } from "resend";

beforeEach(async () => {
  loadEnvConfig(process.cwd());
});

test("send survey started / payment confirmed email", async () => {
  const resend = new Resend(process.env.RESEND_API_KEY);
  const generateId = () => Math.random().toString(36).substring(7);
  const fakeSurveyId = generateId();
  const fakePaymentIntent = "pi_" + generateId();

  const { data, error } = await resend.emails.send({
    from: "Some company <support@mycompany.com>",
    to: "sam@mycompany.com",
    subject: "Your survey is live!",
    react: PaidSurveyLive({
      survey: {
        audience: "uk",
        question:
          "How likely are people to support a coffee brand that is environmentally friendly (test)",
        size: 1,
        id: fakeSurveyId,
      },
      paymentDetails: {
        date: new Date().toDateString(),
        discount: 0,
        total: 7900,
        paymentIntentId: fakePaymentIntent,
        paymentMethod: {
          type: "other",
          last4: "4242",
        },
        subtotal: 7900,
        tax: 0,
      },
      enviroment: process.env.NEXT_PUBLIC_ENVIROMENT === "production" ? "production" : "staging",
      previewText: "Your survey is live! Click the button below to view your survey results.",
    }),
  });

  expect(data).toBeDefined();
  expect(error).toBeNull();
});

Reproduction

I'm not sure how I could reproduce this as it is related to local enviorment variables.

System Info

I'm using Next.js 14 with .env file

Used Package Manager

npm

Validations

Copy link

Hello @samducker. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@sheremet-va
Copy link
Member

I'm not sure how I could reproduce this as it is related to local enviorment variables.

I need a repository that I can open in VSCode and see the error. It doesn't matter if the code is the same that you have right now - you can use code from examples and create a reproducible repo there.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants