drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.54k stars 643 forks source link

Drizzle kit is using the wrong paths seemingly #3465

Open jakeleventhal opened 10 months ago

jakeleventhal commented 10 months ago

I have the following docker compose

  setup-db:
    build:
      dockerfile: ./tools/Dockerfile
    environment:
      DATABASE_URL: postgresql://postgres:local@db:5432/postgres
    command: drizzle-kit push:pg

And the following dockerfile

FROM node:18.17.1-alpine

WORKDIR /app

RUN npm install -g drizzle-kit@latest drizzle-orm@latest
RUN npm install drizzle-orm

# Copy source files
COPY apps/client/package.json ./
COPY packages/database/drizzle.config.ts ./
COPY packages/database/src/schema.ts ./src/schema.ts

This works just fine, but it only seems to work if i have drizzle-orm installed globally and in the local scope. Otherwise, I get this error:

Error: Cannot find module 'drizzle-orm/pg-core'
Require stack:
- /usr/local/lib/node_modules/drizzle-kit/bin.cjs
    at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
    at Module._load (node:internal/modules/cjs/loader:922:27)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at src/serializer/pgImports.ts (/usr/local/lib/node_modules/drizzle-kit/bin.cjs:12133:22)
    at __init (/usr/local/lib/node_modules/drizzle-kit/bin.cjs:9:56)
    at src/utils.ts (/usr/local/lib/node_modules/drizzle-kit/bin.cjs:60390:5)
    at __init (/usr/local/lib/node_modules/drizzle-kit/bin.cjs:9:56)
    at Object.<anonymous> (/usr/local/lib/node_modules/drizzle-kit/bin.cjs:62041:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/usr/local/lib/node_modules/drizzle-kit/bin.cjs' ]
eknowles commented 10 months ago

FWIW I've been getting this issue in bun also

deadcoder0904 commented 9 months ago

@jakeleventhal i don't think it is an error.

see my repo as it is similar (except i use sqlite) -> https://github.com/deadcoder0904/easypanel-nextjs-sqlite

i dont use drizzle-kit at all in production in Dockerfile. i do need migrate command though.

highly recommend reading through these guides:

  1. https://notiz.dev/blog/prisma-migrate-deploy-with-docker
  2. https://notiz.dev/blog/dockerizing-nestjs-with-prisma-and-postgresql

edit: oops, i forgot you use it for drizzle studio. haven't got that running yet but thanks for the solution.

i do think drizzle with docker is a pain-in-the-ass. very few resources on it too.