Closed gutrapp closed 1 year ago
Hello @gutrapp, I've been using t3 stack for a while now and I'm willing to try helping you on this.
I will ask you a couple of questions, just to make sure you're doing everything properly:
src/env/schema.mjs
?env
variable from src/env/server.mjs
?Hi thanks for reaching out:
Did you define the schema of your environment variables in src/env/schema.mjs? Yes I did, example: [... all of the other envs that come with the template] EMAIL_SERVER: z.string(), EMAIL_FROM: z.string()
Did you hard restart your server after adding your new environment variables to the .env file? If you mean a server on Vercel, no I didn't because im not using it, but after adding the .env variables I always saved everything got the same error
When trying to access the environment variables are you using the exported env variable from src/env/server.mjs? Yes.
- Did you hard restart your server after adding your new environment variables to the .env file? If you mean a server on Vercel, no I didn't because im not using it, but after adding the .env variables I always saved everything got the same error
I meant the dev server, so after adding your environment variables to the .env file, did you stop your dev server completely and run it again from the terminal?
Every time you add a new environment variable, you need to restart the server completely so the environment variables get loaded properly.
Also it would be very helpful if you can create a minimal repository that can reproduce the issue that you're seeing.
I got it to work, i don't know how but it works now. I just closed now it works again, maybe just a vscode glitch or idk thanks for trying to help tho, appreciate
I have/had the same problem. The problem comes from using the environment variable setup from t3 in your middleware. The middleware is also replacing the process.env in the middleware, hence, we are not able to use the server variables.
Edit: The issue describes this pretty well: https://github.com/vercel/next.js/issues/30612#issuecomment-955065804
Provide environment information
error - Failed to load env from D:\projects\imdb-clone.env TypeError: Cannot read properties of undefined (reading 'split')
❌ Invalid environment variables: DATABASE_URL: Required NEXTAUTH_URL: Required EMAIL_SERVER: Required EMAIL_FROM: Required
const _serverEnv = serverSchema.safeParse(process.env); console.log(serverSchema.safeParse(process.env)) { success: false, error: ZodError: [ { "code": "invalid_type", "expected": "string", "received": "undefined", "path": [ "DATABASE_URL" ], "message": "Required" }, { "code": "invalid_type", "expected": "string", "received": "undefined", "path": [ "NEXTAUTH_URL" ], "message": "Required" }, { "code": "invalid_type", "expected": "string", "received": "undefined", "path": [ "EMAIL_SERVER" ], "message": "Required" }, { "code": "invalid_type", "expected": "string", "received": "undefined", "path": [ "EMAIL_FROM" ], "message": "Required" } ]
Describe the bug
Somehow the program ins't reading the .env variables and saying that they are "Required" even tho I had pu them all with values on the .env and on the .env.example. Then I did a quick console.log on the schema after it's been checked and got that, and there it said it got undefined. I don't understand why it can't read the variables, and the weirdest part is that this is the first time this is happening, my first project I used Instagram auth and it worked flawlessly. Just a reminder I done everything correctly, placed the EMAIL_SERVER and EMAIL_FROM on the and their respective values on the .env file, so I don't undersantd why it isn't working properly. And it gets even weirder because when I push the database it works? So what im trying to say is that it is reading the .env file but at the same time it isn't? Because prisma is connecting to the database.Can someone please help
To reproduce
To be honest I could even tell you how to reproduce because I didn't do anything out of the ordinary, create the t3 template changed from discord provider to email, pushed the prisma database, then when i tried to do run the program, it just didn't work.
Additional information
No response