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

> cheerio@1.2.0 ships CommonJS and ESM builds. Dual package — require() works on Node.js 20, 22, 24 and 26, fails on 18; import works too.

The fast, flexible & elegant library for parsing and manipulating HTML and XML.

Last verified Sep 9, 2026 against cheerio@1.2.0.

cheerio publishes both a CommonJS entry and a native ESM entry (ESM added in 1.0.0). require("cheerio") works on Node.js 20, 22, 24 and 26 but fails on Node.js 18 (ReferenceError). The package declares Node.js >=20.18.1. import "cheerio" works alongside it.

## What to do

1. Nothing to change. require("cheerio") works on Node.js 20, 22, 24 and 26 but fails on Node.js 18 (ReferenceError). The package declares Node.js >=20.18.1. import * as cheerio from "cheerio" works alongside it; use named imports for what the ESM entry exports.
2. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 1.2.0 (Jan 23, 2026)
- Module format: Dual (CommonJS + ESM)
- Last CommonJS version: 1.2.0
- Native ESM since: 1.0.0
- TypeScript types: bundled
- Node engines: >=20.18.1
- Weekly downloads: 24.1M
- License: MIT

## Runtime test results for cheerio@1.2.0

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

| Runtime | require("cheerio") | import "cheerio" |
|---|---|---|
| Node.js 18 | fails (ReferenceError) | fails (ReferenceError) |
| 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 cheerio

ES modules:

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

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

CommonJS:

```js
const cheerio = require("cheerio");
```

## Module format by version

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

| Versions | Format | First published |
|---|---|---|
| 1.0.0 – 1.2.0 | Dual (CommonJS + ESM) | Aug 9, 2024 |
| 0.0.3 – 0.22.0 | CommonJS | Nov 1, 2011 |

## Frequently asked

**Is cheerio ESM-only?**

cheerio@1.2.0 ships CommonJS and ESM builds. cheerio publishes both a CommonJS entry and a native ESM entry (ESM added in 1.0.0). require("cheerio") works on Node.js 20, 22, 24 and 26 but fails on Node.js 18 (ReferenceError). The package declares Node.js >=20.18.1. import "cheerio" works alongside it.

**Can I require cheerio?**

Yes. cheerio ships a CommonJS entry alongside the native ESM entry. require("cheerio") works on Node.js 20, 22, 24 and 26 but fails on Node.js 18 (ReferenceError). The package declares Node.js >=20.18.1.

**Does cheerio work in Bun?**

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

**Does cheerio ship TypeScript types?**

Yes. cheerio bundles its own type declarations; no @types package is needed.

## Links

- [cheerio on npm](https://www.npmjs.com/package/cheerio)
- [Source repository](https://github.com/cheeriojs/cheerio)
- [HTML version](https://canirequire.com/package/cheerio/)
- [JSON version](https://canirequire.com/package/cheerio.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.
