environment variables undefined in drizzle.config.ts

I have my config set up like this:
import { type Config } from "drizzle-kit";

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not set!");
}

export default {
schema: "src/server/db/schema.ts",
driver: "pg",
out: "drizzle/migrations",
dbCredentials: {
connectionString: process.env.DATABASE_URL,
},
} satisfies Config;
import { type Config } from "drizzle-kit";

if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is not set!");
}

export default {
schema: "src/server/db/schema.ts",
driver: "pg",
out: "drizzle/migrations",
dbCredentials: {
connectionString: process.env.DATABASE_URL,
},
} satisfies Config;
But when I try to run
db:generate
db:generate
from my scripts, it throws my error designed to catch when
process.env.DATABASE_URL
process.env.DATABASE_URL
is undefined. I can't figure out why it's coming up as undefined here though since it definitely does have a value, it even works when running migrations and such. I used create-t3-app for this project btw
3 Replies
bloberenober
bloberenober10mo ago
drizzle-kit doesn't automatically load values from .env for now, so you need to use the dotenv package.
zendev
zendev10mo ago
Got it thanks
Louistiti
Louistiti10mo ago
npm
dotenv-cli
A global executable to run applications with the ENV variables loaded by dotenv. Latest version: 7.3.0, last published: a month ago. Start using dotenv-cli in your project by running npm i dotenv-cli. There are 194 other projects in the npm registry using dotenv-cli.