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
Neto6mo 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
Elite6mo ago
dev my .env is set tho same names and everything
Neto
Neto6mo ago
Use .env.local to load environment variables
Elite
Elite6mo ago
whats the diff between .env and .env.local is there a diff?
Neto
Neto6mo ago
nextjs wants .local.env ¯\_(ツ)_/¯
Elite
Elite6mo 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
Elite6mo ago
Env
Never build your apps with invalid environment variables again. Validate and transform your environment with the full power of Zod.
Elite
Elite6mo ago
yo sorry for the ping do you have any idea? its still doing that is something wrong with t3-env?
Neto
Neto6mo ago
is the issue with the environment or setting neon?
Elite
Elite6mo 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
Neto6mo ago
what is even the issue? you ping me without saying i cant help if you dont give me the error
Elite
Elite6mo 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
Neto6mo 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
Elite6mo ago
Ok
Want results from more Discord servers?
Add your server