canirequire

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

  1. 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.
  2. TypeScript: npm install -D @types/underscore
Latest
1.13.8 (Feb 19, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
1.13.8
Native ESM since
1.13.0
TypeScript types
@types/underscore
Node engines
not declared
Weekly downloads
20.1M
License
MIT

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.

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

VersionsFormatFirst published
1.13.0 – 1.13.8Dual (CommonJS + ESM)Apr 9, 2021
1.0.3 – 1.12.1CommonJSDec 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

Similar popularity