DRIZZLE + NEXTJS App router + Supabase Error postgres js timeout

this is my code
"use server";

import { db } from "@/db";
import { users } from "@/db/schema";
import { auth } from "@clerk/nextjs"
import { eq } from "drizzle-orm";

export async function checkUser() {
try {
const { sessionClaims } = auth()

const user = await db.select().from(users).where(eq(users.email, sessionClaims?.email as string))

console.log(user)

if (user === undefined) {
const res = await db.insert(users).values({
email: sessionClaims?.email as string,
nama: `${sessionClaims?.first_name} ${sessionClaims?.last_name}`,
nombor_telefon: '',
negeri: ''
}).returning()

console.log("user takde")

return res
}
} catch (err) {
console.log("error")
console.log(err)
}

}
"use server";

import { db } from "@/db";
import { users } from "@/db/schema";
import { auth } from "@clerk/nextjs"
import { eq } from "drizzle-orm";

export async function checkUser() {
try {
const { sessionClaims } = auth()

const user = await db.select().from(users).where(eq(users.email, sessionClaims?.email as string))

console.log(user)

if (user === undefined) {
const res = await db.insert(users).values({
email: sessionClaims?.email as string,
nama: `${sessionClaims?.first_name} ${sessionClaims?.last_name}`,
nombor_telefon: '',
negeri: ''
}).returning()

console.log("user takde")

return res
}
} catch (err) {
console.log("error")
console.log(err)
}

}
This is the error
1 Reply
farhan
farhanOP8mo ago
Error: write CONNECTION_ENDED aws-0-ap-southeast-1.pooler.supabase.com:6543
at Query.handler (webpack-internal:///(rsc)/./node_modules/postgres/src/index.js:328:74)
at Query.handle (webpack-internal:///(rsc)/./node_modules/postgres/src/query.js:145:65) {
code: 'CONNECTION_ENDED',
errno: 'CONNECTION_ENDED',
address: [ 'aws-0-ap-southeast-1.pooler.supabase.com' ],
port: [ 6543 ]
}
undefined
TypeError: Cannot redefine property: query
at Function.defineProperties (<anonymous>)
at queryError (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:403:12)
at errored (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:399:17)
at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:333:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
node_modules/postgres/src/connection.js (388:0) @ queryError
uncaughtException: TypeError: Cannot redefine property: query
at Function.defineProperties (<anonymous>)
at queryError (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:403:12)
at errored (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:399:17)
at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:333:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
Error: write CONNECTION_ENDED aws-0-ap-southeast-1.pooler.supabase.com:6543
at Query.handler (webpack-internal:///(rsc)/./node_modules/postgres/src/index.js:328:74)
at Query.handle (webpack-internal:///(rsc)/./node_modules/postgres/src/query.js:145:65) {
code: 'CONNECTION_ENDED',
errno: 'CONNECTION_ENDED',
address: [ 'aws-0-ap-southeast-1.pooler.supabase.com' ],
port: [ 6543 ]
}
undefined
TypeError: Cannot redefine property: query
at Function.defineProperties (<anonymous>)
at queryError (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:403:12)
at errored (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:399:17)
at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:333:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
node_modules/postgres/src/connection.js (388:0) @ queryError
uncaughtException: TypeError: Cannot redefine property: query
at Function.defineProperties (<anonymous>)
at queryError (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:403:12)
at errored (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:399:17)
at Socket.data (webpack-internal:///(rsc)/./node_modules/postgres/src/connection.js:333:9)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:335:12)
at readableAddChunk (node:internal/streams/readable:308:9)
at Readable.push (node:internal/streams/readable:245:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
I've tried googling but couldnt find any solutions Also don't know which part i did wrong
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
import * as schema from "./schema"

const connectionString = process.env.DATABASE_URL!
const sql = postgres(connectionString)
export const db = drizzle(sql, {
schema
});
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
import * as schema from "./schema"

const connectionString = process.env.DATABASE_URL!
const sql = postgres(connectionString)
export const db = drizzle(sql, {
schema
});
nvm solved, Deleted node modules and bun lock reinstalling back everything resolve the issue
Want results from more Discord servers?
Add your server