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

> pg@8.23.0 ships CommonJS and ESM builds. Dual package — require() works on every Node.js version we test; import works too.

PostgreSQL client - pure javascript & libpq with the same API

Last verified Sep 9, 2026 against pg@8.23.0.

pg publishes both a CommonJS entry and a native ESM entry (ESM added in 8.15.0). require("pg") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 16.0.0. import "pg" works alongside it.

## What to do

1. Nothing to change. require("pg") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 16.0.0. import * as pg from "pg" works alongside it; use named imports for what the ESM entry exports.
2. TypeScript: npm install -D @types/pg

## Facts

- 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

## Runtime test results for pg@8.23.0

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.0 | works | works |

## How to import pg

ES modules:

```js
import * as pg from "pg";
```

Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.

CommonJS:

```js
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") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 16.0.0. import "pg" works alongside it.

**Can I require pg?**

Yes. pg ships a CommonJS entry alongside the native ESM entry. require("pg") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. The package declares Node.js >= 16.0.0.

**Does pg work in Bun?**

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

**Does pg ship TypeScript types?**

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

## Links

- [pg on npm](https://www.npmjs.com/package/pg)
- [Source repository](https://github.com/brianc/node-postgres)
- [HTML version](https://canirequire.com/package/pg/)
- [JSON version](https://canirequire.com/package/pg.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
