Drizzle and Deno 2
I bumped into a bunch of issues when I initially tried setting up drizzle-orm
and drizzle-kit
in a Deno 2/Fresh project because of module resolutions issues. After poking around for a bit longer than I would have liked, I suddenly remembered this bit in the Deno 2 RC release notes:
// deno.json
{
"nodeModulesDir": "auto"
}
With that added to the Deno config, running deno install
on an NPM package will automatically create a node_modules
directory for those dependencies. For example, for Drizzle with Postgres:
deno install npm:dotenv npm:drizzle-orm npm:drizzle-kit npm:postgres
You don't need to rely on any node package managers (npm
, yarn
, or pnpm
) and you shouldn't get a package.json
file.
Note that if you are reading environment variables in drizzle.config.ts
, you will need dotenv
for reading environment variables because drizzle-kit
runs in the context of Node.js. For example:
// drizzle.config.ts
import "dotenv/config";
import { defineConfig } from "drizzle-kit";
import process from "node:process";
export default defineConfig({
out: "./drizzle",
schema: "./db/schema",
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});