canirequire › Dual (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.
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.
| Runtime | require("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).
| Versions | Format | First published |
|---|---|---|
| 8.15.0 – 8.23.0 | Dual (CommonJS + ESM) | Apr 22, 2025 |
| 7.17.0 – 8.14.1 | CommonJS | Dec 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
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- is-boolean-object 1.2.2CommonJS
- typed-array-buffer 1.0.3CommonJS
- react-router 8.3.1ESM-only
- string-length 7.0.1ESM-only
- supports-preserve-symlinks-flag 1.0.0CommonJS
- jest-snapshot 30.5.1Dual
- core-js-compat 3.50.0CommonJS
- has-bigints 1.1.0CommonJS