drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

cause: TypeError: Cannot read properties of undefined (reading 'searchParams')

Open deniznet opened this issue 2 months ago • 2 comments

Hi! I've just try Drizzle! Make step-by-step https://orm.drizzle.team/docs/get-started/postgresql-new So, after npx drizzle-kit migrate, got error:

No config path provided, using default 'drizzle.config.ts'
Reading config file 'C:\Users\me\Documents\proj\testnextjs\testnextjsapp\drizzle.config.ts'
Using 'pg' driver for database querying
[⣷] applying migrations...DrizzleQueryError: Failed query: CREATE SCHEMA IF NOT EXISTS "drizzle"
params:
    at NodePgPreparedQuery.queryWithCache (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\src\pg-core\session.ts:73:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5) {
  query: 'CREATE SCHEMA IF NOT EXISTS "drizzle"',
  params: [],
  cause: TypeError: Cannot read properties of undefined (reading 'searchParams')
      at parse (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg-connection-string\index.js:39:30)
      at new ConnectionParameters (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg\lib\connection-parameters.js:56:42)
      at new Client (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg\lib\client.js:18:33)
      at BoundPool.newClient (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg-pool\index.js:233:20)
      at BoundPool.connect (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg-pool\index.js:227:10)
      at BoundPool.query (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\pg-pool\index.js:411:10)
      at <anonymous> (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\src\node-postgres\session.ts:149:27)
      at NodePgPreparedQuery.queryWithCache (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\src\pg-core\session.ts:71:18)
      at <anonymous> (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\src\node-postgres\session.ts:148:18)
      at Object.startActiveSpan (C:\Users\me\Documents\proj\testnextjs\testnextjsapp\node_modules\src\tracing.ts:27:11)

What's the "searchParams" and what happend?

My schema.ts:

import { integer, pgTable, varchar } from "drizzle-orm/pg-core";
export const usersTable = pgTable("users", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  name: varchar({ length: 255 }).notNull(),
  password: varchar({ length: 255 }).notNull(),
  email: varchar({ length: 255 }).notNull().unique(),
},);

drizzle.config.ts:

import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
  out: './drizzle',
  schema: './src/db/schema.ts',
  dialect: 'postgresql',
  dbCredentials: {
    url: process.env.DATABASE_URL!,
  },
});

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    ".next/types/**/*.ts",
    ".next/dev/types/**/*.ts",
    "**/*.mts"
  ],
  "exclude": [
    "node_modules"
  ]
}

What happend? What I should do? Thank you!

deniznet avatar Nov 01 '25 07:11 deniznet

Hi @deniznet, after some refactoring this morning I had the same issue.

Turns out that I messed up with my DATABASE_URL env variable. Once I fixed it, it worked again

bmichotte avatar Nov 02 '25 13:11 bmichotte

Hi @deniznet, after some refactoring this morning I had the same issue.

Turns out that I messed up with my DATABASE_URL env variable. Once I fixed it, it worked again

Oh! Thank you for your answer! It good idea to solve! I didn't miss up DATABASE_URL, but it inclouds another vars, like: DATABASE_URL='postgresql://${PGDB_USERNAME}:${PGDB_PASSWORD}@pgdb/${PGDB_DATABASE}?schema=public&connect_timeout=300'

When I wrote it without ${some_var}, it has run Ok! Also, I run all in Docker. May be it's enough for this topic, but if anybody discribe "why isn't work with subvar" it will be perfect! In any case, Thank you!

deniznet avatar Nov 02 '25 16:11 deniznet