Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T3 App `❌ Invalid environment variables:`

I'm using the T3-app (nextjs, tRPC, etc), and I don't know if these env variable errors just happened, or if I haven't noticed them before. However, I have all of the environment variables set in the .env file and have the following configuration set in the schema.mjs file:

export const serverSchema = z.object({
    DATABASE_URL: z.string().url(),
    NODE_ENV: z.enum(["development", "test", "production"]),
    NEXTAUTH_SECRET: z.string(),
    NEXTAUTH_URL: z.preprocess(
        // This makes Vercel deployments not fail if you don't set NEXTAUTH_URL
        // Since NextAuth automatically uses the VERCEL_URL if present.
        (str) => process.env.VERCEL_URL ?? str,
        // VERCEL_URL doesnt include `https` so it cant be validated as a URL
        process.env.VERCEL ? z.string() : z.string().url(),
    ),
    GOOGLE_CLIENT_ID: z.string(),
    GOOGLE_CLIENT_SECRET: z.string(),
    STRIPE_SECRET_KEY: z.string(),
});

export const serverEnv = {
    DATABASE_URL: process.env.DATABASE_URL,
    NODE_ENV: process.env.NODE_ENV,
    NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
    GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
    GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
    NEXTAUTH_URL: process.env.NEXTAUTH_URL,
    STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
};

However, the process.env object is undefined. The only one that has a value is NODE_ENV but it isn't any different than the rest of the env variables.

I'm pretty lost on why this is happening. I've looked up this problem, but nothing is coming up. Am I doing something incorrectly?

The env var errors

like image 721
Ygbh Avatar asked May 02 '26 06:05

Ygbh


2 Answers

I am one of the early maintainers and idea people for T3 & Ct3A

So the beating heart of Create T3 App, is NextJS, this is likely just a small issue with how you are implementing the .env not aligning with how NextJS is expecting the file.

For a local dev environment the env file should be -> .env.local for more details on how to do environment variables and file structure here are the NextJS docs relevant to this problem.

like image 70
Jacob Avatar answered May 06 '26 12:05

Jacob


If the error is like this

❌ Invalid environment variables: {
  DISCORD_CLIENT_ID: [ 'Required' ],
  DISCORD_CLIENT_SECRET: [ 'Required' ]
}

and you're trying out T3. The fix is:

  1. Make sure your Node version is >= 18. To check run node -v.
  2. During the app creation prompt, select "None" for the "What authentication provider would you like to use?" question
like image 27
sanjarcode Avatar answered May 06 '26 12:05

sanjarcode