Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

177
Views
is there a way to import { pool } from pg

I'm trying to import Pool, but i am getting an error.

This is the error, which get thrown:

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.

This is my code:

import { Pool } from "pg";

dotenv.config();

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

export default pool;
7 months ago · Santiago Gelvez
1 answers
Answer question

0

You should use the default export:

import pg from "pg";
const { Pool } = pg;
dotenv.config();

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

export default pool;
7 months ago · Santiago Gelvez Report
Answer question
Find remote jobs