pg.Pool不是构造函数 [英] pg.Pool is not a constructor

查看:87
本文介绍了pg.Pool不是构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用此代码的谷歌云功能,它给出了错误TypeError :pg.Pool不是exports.postgresDemo的构造函数,我有

I have a google cloud function using this code and it gives the error TypeError: pg.Pool is not a constructor at exports.postgresDemo I have

    {
  "dependencies": {
    "pg": "^2.0.5"
  }
}

作为依赖项.我不知道该错误是节点还是云功能

as the dependencies. I don't know if the error is in node or cloud functions

推荐答案

从您的依赖项中应该很明显:

Should have been obvious from your dependencies :

"dependencies": {
    "pg": "^2.0.5"
  }
}

我跑了这个

const pg = require('pg')
const pool = new pg.Pool()
console.log(pool)

并获得了预期的结果.区别在于,在我的依赖项中,我有:"pg": "^7.7.1".您正在使用的google示例还使用了较新的pg版本. 我尝试安装您的版本以使用npm install pg@2.0.5进行仔细检查,但收到错误:npm ERR! notarget No matching version found for pg@2.0.5 因此升级pg,它将起作用

and got the expected result. Difference is, in my dependencies, I have :"pg": "^7.7.1". The google example you are using also uses a more recent version of pg. I tried to install your version to double check using npm install pg@2.0.5 but got the error: npm ERR! notarget No matching version found for pg@2.0.5 So upgrade pg and it will work

这篇关于pg.Pool不是构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆