canirequire › Dual (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.
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.
| Runtime | require("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).
| Versions | Format | First published |
|---|---|---|
| 5.0.0 – 9.0.0 | Dual (CommonJS + ESM) | Nov 8, 2020 |
| 1.0.0 – 4.0.4 | CommonJS | Mar 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
- 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
- http-proxy-agent 9.1.0ESM-only
- get-caller-file 2.0.5CommonJS
- serve-static 2.2.1CommonJS
- parent-module 3.2.0ESM-only
- ci-info 4.4.0CommonJS
- call-bind-apply-helpers 1.0.2CommonJS
- json-buffer 3.0.1CommonJS
- fresh 0.5.2CommonJS