Skip to content

[BUG]: drizzle-kit pull fails on MSSQL with "Cannot read properties of null (reading 'replace')" #5220

@david-sfernandes

Description

@david-sfernandes

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

1.0.0-beta.8-734e789

What version of drizzle-kit are you using?

1.0.0-beta.8-734e789

Other packages

No response

Describe the Bug

Description

I'm trying to use drizzle-kit pull to introspect an existing SQL Server (MSSQL) database, but the command fails with a runtime error during the introspection phase.

The connection itself works, but the process crashes after attempting to fetch database metadata.

Environment

Database: Microsoft SQL Server Azure
Node.js: 24.4.1
Package manager: pnpm
OS: Linux

Message example:

pnpm drizzle-kit pull --init
No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/MYUSER/projects/MY-PROJECT/apps/api/drizzle.config.ts'
[[email protected]] injecting env (0) from .env -- tip: ⚙️  write to custom object with { processEnv: myObject }
[⣽] 0 tables fetching
[⣽] 0 columns fetching
[⣽] 0 enums fetching
[⣽] 0 indexes fetching
[⣽] 0 foreign keys fetching
[⣽] 0 policies fetching
[⣽] 0 check constraints fetching
[⣽] 0 views fetching
 Error  Cannot read properties of null (reading 'replace')

My drizzle.config.ts:

import * as dotenv from "dotenv"
import { defineConfig } from "drizzle-kit"

dotenv.config({ path: ".env" })

if (
  !process.env.DB_HOST ||
  !process.env.DB_NAME ||
  !process.env.DB_USER ||
  !process.env.DB_PASSWORD ||
  !process.env.DATABASE_URL
) {
  throw new Error("DATABASE_URL is not set")
}

export default defineConfig({
  out: "./drizzle",
  schema: "./src/db/schema.ts",
  dialect: "mssql",
  verbose: true,
  dbCredentials: {
    server: process.env.DB_HOST,
    database: process.env.DB_NAME,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    port: 1433,
    // OBS: I try to use only DATABASE_URL, but it leads to another error:
    // The "config.server" property is required and must be of type string.
    // url: process.env.DATABASE_URL
    options: {
      encrypt: true,
      trustServerCertificate: true,
    },
  },
});

Steps to reproduce (following the get started tutorial)

  1. Install the dependecies
  2. set env vars
  3. create drizzle folder and src/db/index.ts
  4. create drizzle.config.ts
  5. run pnpm drizzle-kit pull --init

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions