我最近不得不将我的 vue.js 应用程序(后端的 node.js)的 node.js 版本从 v13.5.0 升级到 v14.5.0。我重新安装了所有 Node 包,升级了我必须升级的那些,现在应用程序卡在所有数据库调用上。我们使用 pg (node-postgres) 来调用我们的数据库。我将 pg 升级到 7.18.2 版。
我们的初始化代码如下所示:
constructor() {
this.pg = require('pg');
this.client = null;
this.initPromise = null;
}
async init() {
if (!this.initPromise) {
this.client = new this.pg.Client({
application_name: 'Back end',
ssl: {
rejectUnauthorized: false
}
});
this.initPromise = this.client.connect();
}
return this.initPromise;
}
async query(query, params) {
await this.init();
return await this.client.query(query, params);
}
我将控制台日志放在对 this.init() 的调用中,如下所示:console.log('before');
await this.init();
console.log('after');
'after' 永远不会打印出来。有谁知道为什么我升级了 Node 版本后它会挂起?
最佳答案
看来 pg v.8.3.0 解决了这个问题。我通过运行 npm install pg 获得了 v7.18.2。似乎并不总是安装最新版本。 npm install pg@latest 可以解决问题。
关于node.js - 为什么当我调用 client.connect() 时 node-postgres (pg) 挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62876107/