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"),