node.js - 无法从 node-pg 导入客户端
问题描述
我正在尝试在 Node 项目中使用 Postgresql。我正在使用模块化导入,因此在导入“pg”时遇到问题:
import * as pg from 'pg'
const { Client } = pg
let client = new Client()
导致这个错误
let client = new Client()
^
TypeError: Client is not a constructor
我已经查看了与此类似的其他几个问题,但仍有问题:
import { native as pg } from 'pg';
let client = new pg.Client()
导致此错误:
import { native as pg } from 'pg';
^^^^^^
SyntaxError: Named export 'native' not found. The requested module 'pg' is a CommonJS module, which may not support all module.exports as named exports.
有谁知道我可以尝试正确进行此导入吗?
解决方案
从错误建议来看,pg 是一个 CommonModule,它可能不支持所有 module.exports 作为命名导出。
更改导入
import * as pg from 'pg'
至
import pg from 'pg'
将解决导入问题。
推荐阅读
- php - 如何使用 laravel 5.4 制作工作菜单选项卡
- django - 如何在 Django Rest Framework 中注册后自动生成电子邮件?
- php - 从商店页面 woocommerce 添加到购物车分组产品
- x86-64 - 将 x86-64 上的 long double 传递给可变参数函数
- r - 从数据帧转换为 sf
- javascript - 我想制作包含 css 和 javascript * .html、* .js 和 * .css 的单独 html 文件
- python - Nuke OFX 插件 - 自定义图标
- wordpress - 在 wordpress 仪表板中提交表单后显示成功消息
- bluetooth - 使用bluez通过蓝牙连接两个树莓派
- database - 我的图像未出现 Codeigniter