79192660

Date: 2024-11-15 13:53:45
Score: 2
Natty:
Report link

Issue 1: Thank you @suresh, first step forward was adding tsconfig.json file to my build.

Issue 2: I had to get the mjs to cjs since the import keyword does not work in mjs. module: CommonJs to the rescue for my server.ts file which I need to manually rename to cjs after build using renamed.

Issue 3: I had the whole application running in FE, meaning the server runs on FE too, so adding VITE_CONFIG_VARIABLE: "string", ; adding VITE_ keyword to all my config variables was needed.

Issue 4: I had to write a function in a separate file to import config values as some values needed process.env and some needed import.meta.env for importing the variables from .env file.

import "dotenv/config";

const getEnvVar = (key: keyof ImportMetaEnv): string => {
  if (
    typeof import.meta !== "undefined" &&
    import.meta.env &&
    import.meta.env[key] !== undefined
  ) {
    return import.meta.env[key] as string;
  } else if (process.env[key] !== undefined) {
    return process.env[key]!;
  }
  throw new Error(`Missing required environment variable: ${key}`);
};

export const environmentVariables = {
  // Square API Configuration
  environment: getEnvVar("VITE_SQUARE_ENVIRONMENT"),

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @suresh
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: aamer saleem