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. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
cheerio publishes both a CommonJS entry and a native ESM entry (ESM added in 1.0.0). require("cheerio") and import "cheerio" both work on every supported Node.js version and in Bun.
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 | ✓ 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 cheerio from "cheerio";CommonJS (require)
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") and import "cheerio" both work on every supported Node.js version and in Bun.
Can I require cheerio?
Yes. cheerio ships a CommonJS entry, so require("cheerio") works on every Node.js version, alongside the native ESM entry for import.
Does cheerio work in Bun?
Yes. import "cheerio" loaded successfully in Bun 1.4 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
- 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
- unique-filename 6.0.0CommonJS
- bindings 1.5.0CommonJS
- joi 18.2.8CommonJS
- ts-jest 29.4.12CommonJS
- whatwg-fetch 3.6.20CommonJS
- colors 1.4.0CommonJS
- @smithy/querystring-parser 4.5.2CommonJS
- validator 13.15.35CommonJS