postgresql 是否有方法从pg导入{ pool }

t3psigkw  于 2022-11-23  发布在  PostgreSQL
关注(0)|答案(1)|浏览(82)

我正在尝试导入池,但遇到错误。
下面是抛出的错误:

import { Pool } from "pg";
         ^^^^
SyntaxError: Named export 'Pool' not found. The requested module 'pg' is a CommonJS module, which may not support all module.exports as named exports.

这是我的代码:

import { Pool } from "pg";

dotenv.config();

const databaseConfig = { connectionString: process.env.DATABASE_URL };
const pool = new Pool(databaseConfig);

export default pool;
6vl6ewon

6vl6ewon1#

应使用默认导出:

import pg from "pg";
const { Pool } = pg;

dotenv.config();

const databaseConfig = { connectionString: process.env.DATABASE_URL };
const pool = new Pool(databaseConfig);

export default pool;

相关问题