canirequire

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

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

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.

Runtimerequire("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).

VersionsFormatFirst published
1.0.0 – 1.2.0Dual (CommonJS + ESM)Aug 9, 2024
0.0.3 – 0.22.0CommonJSNov 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

Similar popularity