Drizzle & Postgres JS - "postgres is not a function"

I'm using NestJS v10.3.6 package-json:
"drizzle-orm": ^0.30.10,
"postgres": ^3.4.4,
"drizzle-orm": ^0.30.10,
"postgres": ^3.4.4,
2024-05-10 01:48:34 [Nest] 53 - 05/09/2024, 6:48:34 PM ERROR [ExceptionsHandler] (0 , postgres_1.default) is not a function
2024-05-10 01:48:34 TypeError: (0 , postgres_1.default) is not a function
2024-05-10 01:48:34 [Nest] 53 - 05/09/2024, 6:48:34 PM ERROR [ExceptionsHandler] (0 , postgres_1.default) is not a function
2024-05-10 01:48:34 TypeError: (0 , postgres_1.default) is not a function
import { Injectable } from '@nestjs/common'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as schema from 'src/schema'

@Injectable()
export class UsersService {
async getAll(): Promise<(typeof schema.users.$inferSelect)[]> {
const client = postgres('postgres://root:root@postgres:5432/testing', { // <== Here's the problem
ssl: false,
})

const db = drizzle(client, { schema })

// queries
}
}
import { Injectable } from '@nestjs/common'
import { drizzle } from 'drizzle-orm/postgres-js'
import postgres from 'postgres'
import * as schema from 'src/schema'

@Injectable()
export class UsersService {
async getAll(): Promise<(typeof schema.users.$inferSelect)[]> {
const client = postgres('postgres://root:root@postgres:5432/testing', { // <== Here's the problem
ssl: false,
})

const db = drizzle(client, { schema })

// queries
}
}
here's what i found inside the /dist directory :
const common_1 = require("@nestjs/common");
const postgres_js_1 = require("drizzle-orm/postgres-js");
const postgres_1 = require("postgres");
const schema = require("../../schema");
let UsersService = class UsersService {
async getAll() {
const client = (0, postgres_1.default)('postgres://root:root@postgres:5432/testing', { // PROBLEM!!
ssl: false,
});
const db = (0, postgres_js_1.drizzle)(client, { schema });
const users = await db.select().from(schema.users);
return users;
}
};
const common_1 = require("@nestjs/common");
const postgres_js_1 = require("drizzle-orm/postgres-js");
const postgres_1 = require("postgres");
const schema = require("../../schema");
let UsersService = class UsersService {
async getAll() {
const client = (0, postgres_1.default)('postgres://root:root@postgres:5432/testing', { // PROBLEM!!
ssl: false,
});
const db = (0, postgres_js_1.drizzle)(client, { schema });
const users = await db.select().from(schema.users);
return users;
}
};
2 Replies
samson
samson6mo ago
If you're using Next, then I'd try and check your server/client components. Are you declaring them correctly? I usually see this error when trying to use a function that should be in a server component (e.g. db.query.... inside a client component.
OACS
OACS5mo ago
Try with import * as postgres from 'postgres';
Want results from more Discord servers?
Add your server