typescript - TypeError: this.postgres.Pool 不是构造函数
我只是想通过使用 typeorm 将我的 nestjs 项目连接到我的 postgresql 数据库。但是遇到了
[Nest] 19603 - 09/06/2022, 1:49:42 PM 错误 [TypeOrmModule] 无法连接到数据库。正在重试 (1)... TypeError: this.postgres.Pool 不是一个构造函数
我使用 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
遇到了同样的问题。你应该删除 "driver": "postgres", 这一行。
在 typeorm 里面,它是这样工作的
const postgres = this.options.driver || PlatformTools_1.PlatformTools.load("pg");
this.postgres = postgres;
// ...
const pool = new this.postgres.Pool(connectionOptions);
所以,在你的情况下,它试图从一个字符串中获取 Pool 属性。
