invalid env variables

So Im using nextjs + drizzle + neon db Ive setup a script to print my databse i get this error:
Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
CLERK_SECRET_KEY: [ 'Required' ],
TAVILY_API_KEY: [ 'Required' ],
GROQ_API_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL: [ 'Required' ]
}
file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29
throw new Error("Invalid environment variables");
^

Error: Invalid environment variables
at onValidationError (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29:15)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:35:16)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-nextjs/dist/index.js:12:12)
at file:///C:/Users/rkmad/partnerfind.tech/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
CLERK_SECRET_KEY: [ 'Required' ],
TAVILY_API_KEY: [ 'Required' ],
GROQ_API_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL: [ 'Required' ]
}
file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29
throw new Error("Invalid environment variables");
^

Error: Invalid environment variables
at onValidationError (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29:15)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:35:16)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-nextjs/dist/index.js:12:12)
at file:///C:/Users/rkmad/partnerfind.tech/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
` here is my env.js: https://gist.github.com/navincodesalot/e91d0cd5ffca574fe1a593ac48ae5311 Here is my server/index.ts: https://gist.github.com/navincodesalot/bfda54ac39a0c5cdf88867fa3ad22eb5 Is there a reason I can't use process.env in my index.ts? am I using it correctly
17 Replies
Neto
Neto8mo ago
on dev or on prod? but from the looks it it, its just not injecting the environment variables you either didnt set them or put a wrong file name
Elite
EliteOP8mo ago
dev my .env is set tho same names and everything
Neto
Neto8mo ago
Use .env.local to load environment variables
Elite
EliteOP8mo ago
whats the diff between .env and .env.local is there a diff?
Neto
Neto8mo ago
nextjs wants .local.env ¯\_(ツ)_/¯
Elite
EliteOP8mo ago
damn alr ty still getting that changed it to .env.local example
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { company } from '@/server/db/schema';
import { env } from '@/env'; // Importing environment configuration

/**
* Cache the Neon database connection in development. This avoids creating a new connection on every HMR update.
*/
const globalForDb = globalThis as unknown as {
conn: ReturnType<typeof neon> | undefined;
};

const sql = globalForDb.conn ?? neon<boolean, boolean>(env.DATABASE_URL!); // Accessing DATABASE_URL from env
if (env.NODE_ENV !== "production") globalForDb.conn = sql;

const db = drizzle(sql);

const allCompanies = await db.select().from(company);

console.log(allCompanies);
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { company } from '@/server/db/schema';
import { env } from '@/env'; // Importing environment configuration

/**
* Cache the Neon database connection in development. This avoids creating a new connection on every HMR update.
*/
const globalForDb = globalThis as unknown as {
conn: ReturnType<typeof neon> | undefined;
};

const sql = globalForDb.conn ?? neon<boolean, boolean>(env.DATABASE_URL!); // Accessing DATABASE_URL from env
if (env.NODE_ENV !== "production") globalForDb.conn = sql;

const db = drizzle(sql);

const allCompanies = await db.select().from(company);

console.log(allCompanies);
Elite
EliteOP8mo ago
Env
Never build your apps with invalid environment variables again. Validate and transform your environment with the full power of Zod.
Elite
EliteOP8mo ago
yo sorry for the ping do you have any idea? its still doing that is something wrong with t3-env?
Neto
Neto8mo ago
is the issue with the environment or setting neon?
Elite
EliteOP8mo ago
its in this file @nyx (Rustular DevRel) you see where i do env.DATABASE_URL! my env.js: https://gist.github.com/navincodesalot/e91d0cd5ffca574fe1a593ac48ae5311 my server/index.ts https://gist.github.com/navincodesalot/bfda54ac39a0c5cdf88867fa3ad22eb5 @nyx (Rustular DevRel) hey sorry to ping again but still confused do you got any idea?
Neto
Neto8mo ago
what is even the issue? you ping me without saying i cant help if you dont give me the error
Elite
EliteOP8mo ago
sorry waht i mean is i still get invalid ENV variables @nyx (Rustular DevRel)
Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
CLERK_SECRET_KEY: [ 'Required' ],
TAVILY_API_KEY: [ 'Required' ],
GROQ_API_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL: [ 'Required' ]
}
file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29
throw new Error("Invalid environment variables");
^

Error: Invalid environment variables
at onValidationError (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29:15)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:35:16)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-nextjs/dist/index.js:12:12)
at file:///C:/Users/rkmad/partnerfind.tech/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
Invalid environment variables: {
DATABASE_URL: [ 'Required' ],
CLERK_SECRET_KEY: [ 'Required' ],
TAVILY_API_KEY: [ 'Required' ],
GROQ_API_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_SIGN_UP_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL: [ 'Required' ],
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL: [ 'Required' ]
}
file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29
throw new Error("Invalid environment variables");
^

Error: Invalid environment variables
at onValidationError (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:29:15)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-core/dist/index.js:35:16)
at createEnv (file:///C:/Users/rkmad/partnerfind.tech/node_modules/@t3-oss/env-nextjs/dist/index.js:12:12)
at file:///C:/Users/rkmad/partnerfind.tech/src/env.js:4:20
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:28:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)
error ^ here is my env.js: https://gist.github.com/navincodesalot/e91d0cd5ffca574fe1a593ac48ae5311 Here is my server/index.ts: https://gist.github.com/navincodesalot/bfda54ac39a0c5cdf88867fa3ad22eb5
Neto
Neto8mo ago
The error still the same Nextjs isn’t reading the env file If even after following the tutorial from their side it doesn’t work Open a issue with them
Elite
EliteOP8mo ago
Ok
metowo
metowo8mo ago
Have you confirmed that a fresh t3 app is reading the env vars before you start fiddling with neon, etc? I noticed that, Lucia auth, for example, reads .env but nextjs wants .env.local. nextjs docs say they honor .env, but it just didn't work like that for me. I think incrementally introducing changes is the way to go
Elite
EliteOP8mo ago
I mean idk. It’s just that the env.js isn’t working I guess
Want results from more Discord servers?
Add your server