canirequire › Dual (CommonJS + ESM) › cheerio
Is cheerio ESM-only? Can you require() it?
The fast, flexible & elegant library for parsing and manipulating HTML and XML.
Last verified Sep 9, 2026 against cheerio@1.2.0. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on Node.js 20, 22, 24 and 26, fails on 18; import works too
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
- 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.
- TypeScript: types are bundled; install nothing extra.
Does cheerio@1.2.0 actually load? Runtime test results
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 | ✗ failsReferenceError | ✗ failsReferenceError |
| 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 |
A failing require() on a CommonJS package usually means the package needs a browser/DOM global, a peer dependency, or a native binary that is not available in a bare Node.js process.
How to import cheerio
ES modules (import)
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 (require)
const cheerio = require("cheerio");Module format by version
Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (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
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- bindings 1.5.0CommonJS
- joi 18.2.8CommonJS
- ts-jest 29.4.12CommonJS
- @babel/preset-react 8.0.1ESM-only
- whatwg-fetch 3.6.20CommonJS
- @aws-sdk/client-sso 3.1128.0CommonJS
- colors 1.4.0CommonJS
- @smithy/querystring-parser 4.5.2CommonJS