node-postgres
node-postgres copied to clipboard
this.Client is not a constructor
Hello there!
I am stuck for a while on it so...
Here is my code :
import pg from "pg";
const { Pool } = pg;
export const pool = new Pool({
host: process.env.PGHOST,
user: process.env.PGUSER,
password: process.env.PGPASSWORD,
database: process.env.PGDATABASE,
port: process.env.PGPORT,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
})
const sqlQuery = "..."
const sqlParam = [...]
let res = await pool.query(sqlQueryTest, sqlParam);
when executing it throws this exception :
/usr/src/app/node_modules/pg-pool/index.js:218
const client = new this.Client(this.options)
^
TypeError: this.Client is not a constructor
at BoundPool.newClient (/usr/src/app/node_modules/pg-pool/index.js:218:20)
at BoundPool.connect (/usr/src/app/node_modules/pg-pool/index.js:212:10)
at BoundPool.query (/usr/src/app/node_modules/pg-pool/index.js:399:10)
at updatePremiumEndDateForCustomer (file:///usr/src/app/actions.js:40:26)
at startSubscription (file:///usr/src/app/actions.js:9:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v20.9.0
Any Idea ?
I am also facing same kinda issue
const client = new Client();
^
TypeError: import_pg.Client is not a constructor
at <anonymous> (/home/nees/kabelinteriorsbackend/pg.ts:2:16)
at Object.<anonymous> (/home/nees/kabelinteriorsbackend/pg.ts:2:20)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Object.S (/usr/local/lib/node_modules/tsx/dist/cjs/index.cjs:1:1292)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at cjsLoader (node:internal/modules/esm/translators:345:17)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
Node.js v20.10.0
I'm facing the same issue. @broisnischal and @Profluens-AntoineO did you figure out a workaround?
I honestly don't remember, but I think I used pg https://www.npmjs.com/package/pg