knex broken after upgrading from Node.js v12 to Node.js v16.4.0

Viewed 484

I'm experiencing below error after upgrading to Node.js v16.4.0 (from Node.js v12).

I'm using knex to connect to db (postgres) and using ORM - objection.js.

KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

Please help to resolve!

import Knex from "knex";

const getConnection = () => {
    try {
        return Knex({
            client: 'pg',
            connection: {
                user: 'user',
                password: 'password',
                host: 'dbhost',
                port: 5432,
                database: 'dbname',
            },
            pool: {
                min: 0,
                max: 10,
                idleTimeoutMillis: 10000,
                acquireTimeoutMillis: 30000,
            },
            acquireConnectionTimeout: 2000,
        });
    }
    catch (err) {
        throw err;
    }
}

const getTransaction = () => {
    const con = getConnection();
    const trx = con.transaction();
    return trx;    
}

1 Answers

Having had the same issue, I traced the problem to an old version of the "pg" package.

Doing

npm i pg@latest

fixed it

Related