canirequire

canirequireDual (CommonJS + ESM) › pg

Is pg ESM-only? Can you require() it?

PostgreSQL client - pure javascript & libpq with the same API

Last verified Sep 9, 2026 against pg@8.23.0. JSON

Dual (CommonJS + ESM) Dual package — both require() and import work

pg publishes both a CommonJS entry and a native ESM entry (ESM added in 8.15.0). require("pg") and import "pg" both work on every supported Node.js version and in Bun.

Latest
8.23.0 (Aug 8, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
8.23.0
Native ESM since
8.15.0
TypeScript types
@types/pg
Node engines
>= 16.0.0
Weekly downloads
46.3M
License
MIT

Does pg@8.23.0 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("pg") from a CommonJS file and import "pg" from an ES module.

Runtimerequire("pg")import "pg"
Node.js 18✓ works✓ works
Node.js 20✓ works✓ works
Node.js 22✓ works✓ works
Node.js 24✓ works✓ works
Node.js 26✓ works✓ works
Bun 1.4✓ works✓ works

How to import pg

ES modules (import)

import pg from "pg";

CommonJS (require)

const pg = require("pg");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (246 versions; the newest 60 shown).

VersionsFormatFirst published
8.15.0 – 8.23.0Dual (CommonJS + ESM)Apr 22, 2025
7.17.0 – 8.14.1CommonJSDec 29, 2019

Frequently asked

Is pg ESM-only?

pg@8.23.0 ships CommonJS and ESM builds. pg publishes both a CommonJS entry and a native ESM entry (ESM added in 8.15.0). require("pg") and import "pg" both work on every supported Node.js version and in Bun.

Can I require pg?

Yes. pg ships a CommonJS entry, so require("pg") works on every Node.js version, alongside the native ESM entry for import.

Does pg work in Bun?

Yes. import "pg" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does pg ship TypeScript types?

Not bundled. Install the community types with "npm install -D @types/pg".

Links

Other dual (commonjs + esm) packages

Similar popularity