Invalid Environment Variables

I am having an issue with accessing my ENVs within my drizzle.config.ts. I'm getting an error about invalid env variables despite them being present and being destructured in the env.mjs Each ENV is listed in the .env wrapped in single quotes.
10 Replies
JudgeJLo
JudgeJLo2y ago
More context: it seems the db:push is being registered as trying to use server envs on the client.
Gravy
Gravy2y ago
Hi, can you paste the error output in a code block?
JudgeJLo
JudgeJLo2y ago
[email protected] db:push drizzle-kit push:mysql --config=./drizzle.config.ts
drizzle-kit: v0.19.1
drizzle-orm: v0.27.0

Reading config file '/Users/jasonlong-hrf/HumanRightFirstDev/docdb/docdb-next/drizzle.config.ts'
:x: Invalid environment variables: {
NODE_ENV: [ 'Required' ],
DATABASE_CONNECTION_STRING: [ 'Required' ],
DATABASE_PASSWORD: [ 'Required' ],
DATABASE_URL: [ 'Required' ],
DATABASE_USERNAME: [ 'Required' ]
}
file:///Users/jasonlong-hrf/HumanRightFirstDev/docdb/docdb-next/node_modules/@t3-oss/env-nextjs/dist/index.mjs:1
import c from"zod";function l(e){let r=e.runtimeEnvStrict??e.runtimeEnv??process.env;if(e.skipValidation)return r;let a=typeof e.client=="object"?e.client:{},o=c.object(a),v=c.object(e.server),s=e.isServer??typeof window>"u",d=v.merge(o),i=s?d.safeParse(r):o.safeParse(r),f=e.onValidationError??(t=>{throw console.error("\u274C Invalid environment variables:",t.flatten().fieldErrors),new Error("Invalid environment variables")}),p=e.onInvalidAccess??(t=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")});return i.success===!1?f(i.error):new Proxy(i.data,{get(t,n){if(typeof n=="string")return!s&&!n.startsWith(e.clientPrefix)?p(n):t[n]}})}var u="NEXT_PUBLIC_";function C({runtimeEnv:e,...r}){return l({...r,clientPrefix:u,runtimeEnvStrict:e})}export{C as createEnv};

Error: Invalid environment variables
drizzle-kit: v0.19.1
drizzle-orm: v0.27.0

Reading config file '/Users/jasonlong-hrf/HumanRightFirstDev/docdb/docdb-next/drizzle.config.ts'
:x: Invalid environment variables: {
NODE_ENV: [ 'Required' ],
DATABASE_CONNECTION_STRING: [ 'Required' ],
DATABASE_PASSWORD: [ 'Required' ],
DATABASE_URL: [ 'Required' ],
DATABASE_USERNAME: [ 'Required' ]
}
file:///Users/jasonlong-hrf/HumanRightFirstDev/docdb/docdb-next/node_modules/@t3-oss/env-nextjs/dist/index.mjs:1
import c from"zod";function l(e){let r=e.runtimeEnvStrict??e.runtimeEnv??process.env;if(e.skipValidation)return r;let a=typeof e.client=="object"?e.client:{},o=c.object(a),v=c.object(e.server),s=e.isServer??typeof window>"u",d=v.merge(o),i=s?d.safeParse(r):o.safeParse(r),f=e.onValidationError??(t=>{throw console.error("\u274C Invalid environment variables:",t.flatten().fieldErrors),new Error("Invalid environment variables")}),p=e.onInvalidAccess??(t=>{throw new Error("\u274C Attempted to access a server-side environment variable on the client")});return i.success===!1?f(i.error):new Proxy(i.data,{get(t,n){if(typeof n=="string")return!s&&!n.startsWith(e.clientPrefix)?p(n):t[n]}})}var u="NEXT_PUBLIC_";function C({runtimeEnv:e,...r}){return l({...r,clientPrefix:u,runtimeEnvStrict:e})}export{C as createEnv};

Error: Invalid environment variables
Gravy
Gravy2y ago
Attempted to access a server-side environment variable on the client, drizzle is set up for the client somehwo
JudgeJLo
JudgeJLo2y ago
That's awkward. I explicitly don't want to expose my connection string lol Shouldn't my flag about skipping validation turn this off though? And I don't it the error on app run, just this function It has to be an issue with the envs themselves. I prefixed it with Next_Public and I'm still getting the exact same issues.
Gravy
Gravy2y ago
try deleting node modules and pruning npm/yarn/pnpm store works for me
JudgeJLo
JudgeJLo2y ago
Yeah, still no dice.
Gravy
Gravy2y ago
if it should be public make sure to put it in the client object
JudgeJLo
JudgeJLo17mo ago
The maintainers tell me that I should import the ENV directly using dotenv in the config.
Coded_58
Coded_5812mo ago
facing same issue
No description
Want results from more Discord servers?
Add your server