Moh*_*san 0 javascript postgresql node.js ecmascript-6
我正在尝试导入 Pool,但出现错误。
这是抛出的错误:
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.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
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.
Run Code Online (Sandbox Code Playgroud)
您应该使用默认导出:
import pg from "pg";
const { Pool } = pg;
dotenv.config();
const databaseConfig = { connectionString: process.env.DATABASE_URL };
const pool = new Pool(databaseConfig);
export default pool;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5151 次 |
| 最近记录: |