canirequire › Dual (CommonJS + ESM) › highlight.js
Is highlight.js ESM-only? Can you require() it?
Syntax highlighting with language autodetection.
Last verified Sep 9, 2026 against highlight.js@11.12.0. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
highlight.js publishes both a CommonJS entry and a native ESM entry (ESM added in 11.0.0). require("highlight.js") and import "highlight.js" both work on every supported Node.js version and in Bun.
Does highlight.js@11.12.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("highlight.js") from a CommonJS file and import "highlight.js" from an ES module.
| Runtime | require("highlight.js") | import "highlight.js" |
|---|---|---|
| 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 | ✓ works | ✓ works |
How to import highlight.js
ES modules (import)
import highlightJs from "highlight.js";CommonJS (require)
const highlightJs = require("highlight.js");Module format by version
Derived from the type, main and exports fields of every stable release on npm (98 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 11.0.0 – 11.12.0 | Dual (CommonJS + ESM) | May 30, 2021 |
| 9.13.0 – 10.7.3 | CommonJS | Oct 13, 2018 |
Frequently asked
Is highlight.js ESM-only?
highlight.js@11.12.0 ships CommonJS and ESM builds. highlight.js publishes both a CommonJS entry and a native ESM entry (ESM added in 11.0.0). require("highlight.js") and import "highlight.js" both work on every supported Node.js version and in Bun.
Can I require highlight.js?
Yes. highlight.js ships a CommonJS entry, so require("highlight.js") works on every Node.js version, alongside the native ESM entry for import.
Does highlight.js work in Bun?
Yes. import "highlight.js" loaded successfully in Bun 1.4 on Sep 9, 2026.
Does highlight.js ship TypeScript types?
Yes. highlight.js 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
- arrify 3.0.0ESM-only
- css-loader 7.1.5CommonJS
- async-function 1.0.0Dual
- didyoumean 1.2.2CommonJS
- ioredis 6.0.0CommonJS
- eslint-plugin-react-refresh 0.5.6ESM-only
- unique-filename 6.0.0CommonJS
- bindings 1.5.0CommonJS