Drizzle-kit can't load env file via t3-env
I'd like to use t3-env to validate my env variables in my Drizzle config file. I've tried importing t3-env in the config.ts file, but I'm hit with the error
SyntaxError: Cannot use import statement outside a module
in env.mjs
, which I find odd since it is explicitly marked as an ES module. Other than this, t3-env works fine with drizzle-orm.
Full Error:
This is my Drizzle config file:
I am I doing something wrong or is this just something drizzle-kit does not support atm?12 Replies
Hi! Just a regular developer over here, did you manage to solve or workaround this issue?
few questions:
- whats your build/dev script
- values of
module
and target
inside tsconfig.json
- value of type
inside package.json (if set)
my best guess atm is youre compiling the code into commonjs and the .mjs file was not included in the compilation
easiest fix would probably be to just use typescript for ~/env.ts
, main reason why they outsourced the package was to be able to use typescript instead of jsdoc in the env config file without messing around with too many options in the different config files (IIRC)Hello. I'm having a similar problem, but, in my case, it seems that the env variables that I have set are not being read so I'm getting a "missing env variables" error from the
createEnv
func.
Is there any way I can make drizzle-kit manually import env variables?
Debugging this I can confirm that the env variables get loaded when building, npm run build
. The only time they don't get read is when trying to push
, generate
, etc. using drizzle-kit.Yes ofcourse, you can manually import process.env using something like
Well yes, Iβve tried that and no dice.
That is currently in use in an app for me, so the general concept works for sure. are your env variables stored in .env or are you using NextJS with .env.local?
Ofc I try it a second time and itβs working. π« possible issue was I was not using dotenv at the correct step.
Could be Β―\_(γ)_/Β―
Well, as long as it's working...
Thank you for helping!
Anytime.
btw, don't forget to mark the thread as done for my OCD's sake @sturlen
the underlying problem is that drizzle-kit support for esm is not working yet, which was confirmed by Andrii Sherman in a another server (it did for a while, but they rolled it back. dotenv is the workaround I'm using for now as well, but the underlying problem is not solved
answer source: https://www.answeroverflow.com/m/1117762215353790484
Answer Overflow
Is it possible to use t3env from a Drizzle config file? - Theo's Ty...
I'm using create-t3-app but I'd like to use Drizzle instead of Prisma. I've managed to get it working, but the one pain point I have is that I can't get t3env t...
Oh absolutely.
However, if you use @t3-oss/env-core you can import it into your drizzle.config.ts file without any issues
Also, as drizzle-kit is only a dev tool anyways, I personally don't mind giving it its own settings in my NextJS app