canirequire

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

Latest
11.12.0 (Aug 12, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
11.12.0
Native ESM since
11.0.0
TypeScript types
Bundled
Node engines
>=12.0.0
Weekly downloads
25.2M
License
BSD-3-Clause

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.

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

VersionsFormatFirst published
11.0.0 – 11.12.0Dual (CommonJS + ESM)May 30, 2021
9.13.0 – 10.7.3CommonJSOct 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

Similar popularity