lodash vs lodash-es
Utility Libraries: lodash vs lodash-es
lodashlodash-esSimilar Packages:

Utility Libraries: lodash vs lodash-es

lodash and lodash-es are popular JavaScript utility libraries that provide helper functions for common programming tasks like array manipulation, object handling, and string operations. lodash is the original package built on CommonJS modules, widely supported across all Node.js and browser environments. lodash-es is a port of lodash that uses ES Module syntax, designed specifically for environments that require native import and export statements without transpilation.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
lodash061,3041.41 MB14320 days agoMIT
lodash-es061,304635 kB14320 days agoMIT

lodash vs lodash-es: Module Systems and Tree-Shaking Compared

Both lodash and lodash-es provide the same set of utility functions for handling arrays, objects, and strings in JavaScript. The core difference lies in how they package these functions for consumption β€” one uses CommonJS and the other uses ES Modules. This choice affects how your bundler processes code and how easily you can remove unused features.

πŸ“¦ Module Format: CommonJS vs ES Modules

lodash uses the CommonJS module system by default.

  • This is the standard for Node.js and works everywhere.
  • Modern bundlers can transform this for browsers without extra setup.
// lodash: CommonJS style (transformed by bundlers)
import { map, filter } from 'lodash';

const numbers = [1, 2, 3];
const doubled = map(numbers, n => n * 2);

lodash-es uses native ES Module syntax.

  • It ships with export statements instead of module.exports.
  • Useful for projects that strictly avoid CommonJS transpilation.
// lodash-es: Native ES Module style
import { map, filter } from 'lodash-es';

const numbers = [1, 2, 3];
const doubled = map(numbers, n => n * 2);

🌲 Tree-Shaking: Removing Unused Code

lodash supports tree-shaking when you use named imports.

  • Bundlers like Webpack and Rollup can detect unused functions.
  • You must avoid importing the whole library (e.g., import _ from 'lodash').
// lodash: Good for tree-shaking
import { debounce } from 'lodash';

// lodash: Bad for tree-shaking (includes everything)
// import _ from 'lodash';

lodash-es was built specifically to enable tree-shaking.

  • It was historically better for this before bundlers improved.
  • Now, lodash performs similarly when used with named imports.
// lodash-es: Good for tree-shaking
import { debounce } from 'lodash-es';

// lodash-es: Bad for tree-shaking (includes everything)
// import _ from 'lodash-es';

πŸ”„ Maintenance and Sync Status

lodash is the primary repository for all updates.

  • Security patches and bug fixes land here first.
  • It is the recommended package by the original maintainer for most uses.
// lodash: Check version consistency
import { version } from 'lodash';
console.log(version); // Always reflects the latest stable release

lodash-es is a port that may lag behind the main package.

  • Updates depend on someone syncing changes from lodash.
  • This creates a risk of missing critical fixes in time-sensitive projects.
// lodash-es: Check version consistency
import { version } from 'lodash-es';
console.log(version); // May be older than the main lodash package

πŸ› οΈ Real-World Scenarios

Scenario 1: Standard Web Application

You are building a React or Vue app using Vite or Webpack.

  • βœ… Best choice: lodash
  • Why? Modern bundlers handle CommonJS tree-shaking well enough, and you get updates faster.
// Recommended approach with lodash
import { chunk, merge } from 'lodash';

const data = chunk([1, 2, 3, 4], 2);

Scenario 2: Strict ES Module Environment

You are working in a environment that refuses CommonJS (e.g., some browser-native setups).

  • βœ… Best choice: lodash-es
  • Why? It avoids transpilation steps for module conversion.
// Required approach for strict ESM
import { chunk, merge } from 'lodash-es';

const data = chunk([1, 2, 3, 4], 2);

Scenario 3: Performance Critical Bundle

You need the smallest possible bundle size.

  • βœ… Best choice: lodash (with named imports) or native methods
  • Why? lodash-es does not offer significant size benefits over lodash anymore.
// Native alternative (no dependency needed)
const data = [1, 2, 3, 4];
const chunks = [];
for (let i = 0; i < data.length; i += 2) {
  chunks.push(data.slice(i, i + 2));
}

🌱 When Not to Use Either

Consider skipping both packages when:

  • You only need one or two functions β€” install single-method packages like lodash.clonedeep instead.
  • You can use native JavaScript methods β€” modern browsers support Array.prototype.map and Object.entries.
  • You are worried about bundle size β€” native methods are free and require no downloads.
// Native alternative to _.map
const items = [1, 2, 3];
const doubled = items.map(n => n * 2);

// Native alternative to _.cloneDeep (for simple objects)
const original = { a: 1 };
const copy = { ...original };

πŸ“Œ Summary Table

Featurelodashlodash-es
Module SystemπŸ“¦ CommonJS🌐 ES Modules
Tree-Shakingβœ… Yes (with named imports)βœ… Yes (native support)
Update SyncπŸš€ Primary source (fastest)⚠️ Ported (may lag)
Bundler SupportπŸ› οΈ UniversalπŸ› οΈ ESM-focused
MaintenanceπŸ‘₯ ActiveπŸ‘₯ Community Port

πŸ’‘ Final Recommendation

lodash is the standard choice πŸ§°β€”great for almost all projects due to better maintenance and universal support. Use named imports to keep bundles small.

lodash-es is a specialized tool πŸ”§β€”perfect only for strict ES Module environments that cannot handle CommonJS. Be aware of potential update delays.

Final Thought: For most modern frontend architectures, lodash with named imports is the safer bet. Always check if native JavaScript features can replace these utilities before adding any dependency.

How to Choose: lodash vs lodash-es

  • lodash:

    Choose lodash for most production projects because it is the source of truth for updates and has better long-term maintenance support. It works seamlessly with modern bundlers like Webpack and Vite when using named imports for tree-shaking. This package is the safest choice for teams that want stability and consistent sync with security patches.

  • lodash-es:

    Choose lodash-es only if you are working in a strict ES Module environment that cannot handle CommonJS interop smoothly. Be aware that this package may lag behind the main lodash package in updates and feature parity. It is suitable for specific edge cases where bundler configuration for CommonJS is not an option.

README for lodash

lodash v4.18.1

The Lodash library exported as Node.js modules.

Installation

Using npm:

$ npm i -g npm
$ npm i --save lodash

In Node.js:

// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');

// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');

// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');

See the package source for more details.

Note:
Install n_ for Lodash use in the Node.js < 6 REPL.

Support

Tested in Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12.
Automated browser & CI test runs are available.