Environment variable not being read for drizzle-kit push.
Answered
VoidPointer posted this in #help-forum
I thought I'd give Drizzle a try instead of Prisma for a new use case, because it looks simpler. After following their guide, and creating this config, then running
The
drizzle-kit push as per the guide, I get an invalid URL error because my env var isn't being read. I'm guessing this is because the Nextjs runtime isn't reading .env because this runs independenly of it. If I hard code the url here the push works fine. What can I do to somehow get the evn read?import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
require('dotenv').config();
export default defineConfig({
out: './drizzle',
schema: './src/drizzle/schema.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL || "",
},
});The
require is merely the last of many attempts to get the variables read, none of which worked.Answered by B33fb0n3
try to do it like this:
import dotenv from 'dotenv';
import { defineConfig } from 'drizzle-kit';
dotenv.config();
export default defineConfig({ ... })4 Replies
@VoidPointer I thought I'd give Drizzle a try instead of Prisma for a new use case, because it looks simpler. After following their guide, and creating this config, then running ` drizzle-kit push` as per the guide, I get an invalid URL error because my env var isn't being read. I'm guessing this is because the Nextjs runtime isn't reading `.env` because this runs independenly of it. If I hard code the url here the push works fine. What can I do to somehow get the evn read?
ts
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
require('dotenv').config();
export default defineConfig({
out: './drizzle',
schema: './src/drizzle/schema.ts',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL || "",
},
});
The `require` is merely the last of many attempts to get the variables read, none of which worked.
try to do it like this:
import dotenv from 'dotenv';
import { defineConfig } from 'drizzle-kit';
dotenv.config();
export default defineConfig({ ... })Answer
@B33fb0n3 try to do it like this:
ts
import dotenv from 'dotenv';
import { defineConfig } from 'drizzle-kit';
dotenv.config();
export default defineConfig({ ... })
Thanks, I had tried that, as one the many attempts I mentioned, but in response to your suggestion, I tried it again, without joy, then again like this. Looks like an older value was somehow "stuck":
dotenv.config({override: true });