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.
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.
lodash uses the CommonJS module system by default.
// 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.
export statements instead of module.exports.// lodash-es: Native ES Module style
import { map, filter } from 'lodash-es';
const numbers = [1, 2, 3];
const doubled = map(numbers, n => n * 2);
lodash supports tree-shaking when you use named imports.
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.
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';
lodash is the primary repository for all updates.
// 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.
lodash.// lodash-es: Check version consistency
import { version } from 'lodash-es';
console.log(version); // May be older than the main lodash package
You are building a React or Vue app using Vite or Webpack.
lodash// Recommended approach with lodash
import { chunk, merge } from 'lodash';
const data = chunk([1, 2, 3, 4], 2);
You are working in a environment that refuses CommonJS (e.g., some browser-native setups).
lodash-es// Required approach for strict ESM
import { chunk, merge } from 'lodash-es';
const data = chunk([1, 2, 3, 4], 2);
You need the smallest possible bundle size.
lodash (with named imports) or native methodslodash-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));
}
Consider skipping both packages when:
lodash.clonedeep instead.Array.prototype.map and Object.entries.// 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 };
| Feature | lodash | lodash-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 |
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.
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.
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.
The Lodash library exported as Node.js modules.
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.
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.