TypeError: this.postgres.Pool is not a constructor

Viewed 35

I'm just trying to connect my nestjs project to my postgresql db by using typeorm. But having

[Nest] 19603 - 09/06/2022, 1:49:42 PM ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)... TypeError: this.postgres.Pool is not a constructor`

I use nestjs ^9.0 , pg ^8.8.0 , typeorm ^0.3.9.

@Module({
  imports: [TypeOrmModule.forRoot({
    "driver": "postgres",
    "type": "postgres",
    "host": dbHost,
    "port": 5432,
    "database": dbName,
    "username": dbUser,
    "password": dbPassword,
    "synchronize": true,
    "logging": true,
    "entities": [
      "src/**/entity/*.ts",
      "dist/**/entity/*.js"
    ]
  })],

1 Answers

Had the same problem. You should remove "driver": "postgres", line.

Inside typeorm it works like that

const postgres = this.options.driver || PlatformTools_1.PlatformTools.load("pg");
this.postgres = postgres;
// ...
const pool = new this.postgres.Pool(connectionOptions);

So, in your case it tries to get Pool property from a string.

Related