canirequire › Dual (CommonJS + ESM) › underscore
Is underscore ESM-only? Can you require() it?
JavaScript's functional programming helper library.
Last verified Sep 9, 2026 against underscore@1.13.8. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
underscore publishes both a CommonJS entry and a native ESM entry (ESM added in 1.13.0). require("underscore") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "underscore" works alongside it.
What to do
- Nothing to change. require("underscore") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as underscore from "underscore" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: npm install -D @types/underscore
Does underscore@1.13.8 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("underscore") from a CommonJS file and import "underscore" from an ES module.
| Runtime | require("underscore") | import "underscore" |
|---|---|---|
| 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.0 | ✓ works | ✓ works |
How to import underscore
ES modules (import)
import * as underscore from "underscore";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const underscore = require("underscore");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 (51 versions; the newest 51 shown).
| Versions | Format | First published |
|---|---|---|
| 1.13.0 – 1.13.8 | Dual (CommonJS + ESM) | Apr 9, 2021 |
| 1.0.3 – 1.12.1 | CommonJS | Dec 7, 2011 |
Frequently asked
Is underscore ESM-only?
underscore@1.13.8 ships CommonJS and ESM builds. underscore publishes both a CommonJS entry and a native ESM entry (ESM added in 1.13.0). require("underscore") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "underscore" works alongside it.
Can I require underscore?
Yes. underscore ships a CommonJS entry alongside the native ESM entry. require("underscore") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
Does underscore work in Bun?
Yes. import "underscore" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does underscore ship TypeScript types?
Not bundled. Install the community types with "npm install -D @types/underscore".
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- @popperjs/core 2.11.8CommonJS
- @openai/codex 0.153.4No entry
- change-case 5.4.4ESM-only
- boxen 8.0.1ESM-only
- i18next 26.4.2Dual
- lodash.clonedeep 4.5.0CommonJS
- storybook 10.6.0ESM-only
- @rollup/plugin-commonjs 29.0.3Dual