canirequire

canirequireDual (CommonJS + ESM) › diff

Is diff ESM-only? Can you require() it?

A JavaScript text diff implementation.

Last verified Sep 9, 2026 against diff@9.0.0. JSON

Dual (CommonJS + ESM) Dual package — both require() and import work

diff publishes both a CommonJS entry and a native ESM entry (ESM added in 5.0.0). require("diff") and import "diff" both work on every supported Node.js version and in Bun.

Latest
9.0.0 (Apr 13, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
9.0.0
Native ESM since
5.0.0
TypeScript types
Bundled
Node engines
>=0.3.1
Weekly downloads
124.1M
License
BSD-3-Clause

Does diff@9.0.0 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("diff") from a CommonJS file and import "diff" from an ES module.

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

ES modules (import)

import diff from "diff";

CommonJS (require)

const diff = require("diff");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (54 versions; the newest 54 shown).

VersionsFormatFirst published
5.0.0 – 9.0.0Dual (CommonJS + ESM)Nov 8, 2020
1.0.0 – 4.0.4CommonJSMar 29, 2011

Frequently asked

Is diff ESM-only?

diff@9.0.0 ships CommonJS and ESM builds. diff publishes both a CommonJS entry and a native ESM entry (ESM added in 5.0.0). require("diff") and import "diff" both work on every supported Node.js version and in Bun.

Can I require diff?

Yes. diff ships a CommonJS entry, so require("diff") works on every Node.js version, alongside the native ESM entry for import.

Does diff work in Bun?

Yes. import "diff" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does diff ship TypeScript types?

Yes. diff bundles its own type declarations; no @types package is needed.

Links

Other dual (commonjs + esm) packages

Similar popularity