Is it possible to use t3env from a Drizzle config file?

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 to validate variables in my Drizzle config file. I've tried importing it normally 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 and runs fine when building the page. Full Error:
Reading config file 'F:\Projects\PROJECTNAME\drizzle.config.ts'
F:\Projects\PROJECTNAME\src\env.mjs:2
import { createEnv } from "@t3-oss/env-nextjs";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1048:15)
at Module._compile (node:internal/modules/cjs/loader:1083:27)
at Module._compile (F:\Projects\PROJECTNAME\node_modules\.pnpm\drizzle-kit@0.18.1\node_modules\drizzle-kit\index.js:16334:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Object.newLoader [as .mjs] (F:\Projects\PROJECTNAME\node_modules\.pnpm\drizzle-kit@0.18.1\node_modules\drizzle-kit\index.js:16338:13)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)

Node.js v18.9.0
Reading config file 'F:\Projects\PROJECTNAME\drizzle.config.ts'
F:\Projects\PROJECTNAME\src\env.mjs:2
import { createEnv } from "@t3-oss/env-nextjs";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:360:18)
at wrapSafe (node:internal/modules/cjs/loader:1048:15)
at Module._compile (node:internal/modules/cjs/loader:1083:27)
at Module._compile (F:\Projects\PROJECTNAME\node_modules\.pnpm\drizzle-kit@0.18.1\node_modules\drizzle-kit\index.js:16334:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Object.newLoader [as .mjs] (F:\Projects\PROJECTNAME\node_modules\.pnpm\drizzle-kit@0.18.1\node_modules\drizzle-kit\index.js:16338:13)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Module.require (node:internal/modules/cjs/loader:1021:19)
at require (node:internal/modules/cjs/helpers:103:18)

Node.js v18.9.0
This is my Drizzle config file:
import type { Config } from "drizzle-kit";
import { env } from "~/env.mjs";

export default {
schema: "./src/server/schema.ts",
out: "./drizzle",
connectionString: env.DATABASE_URL,
} satisfies Config;
import type { Config } from "drizzle-kit";
import { env } from "~/env.mjs";

export default {
schema: "./src/server/schema.ts",
out: "./drizzle",
connectionString: env.DATABASE_URL,
} satisfies Config;
Let me know if this is right place to post this or if a gh issue would be more appropriate
1 Reply
Andrii Sherman
Andrii Sherman13mo ago
drizzle-kit is going to have esm support this week. After that it should work properly