As a software engineer, I’m always on the lookout for tools and libraries that can enhance my development workflow and optimize performance. One such tool is Lodash, a popular JavaScript utility library that makes working with arrays, objects, and other data structures a breeze. However, there’s an important decision to make when incorporating Lodash into a project: should you use the standard lodash package or opt for lodash-es? In this post, I’ll share my insights on why lodash-es might be the better choice for modern JavaScript development, especially when using TypeScript.
Thank me by sharing on Twitter 🙏
Introduction
Lodash has been a staple in the JavaScript community for years, offering a wide range of utility functions that simplify common programming tasks. However, as JavaScript has evolved, so too have the tools and practices we use. With the advent of ES modules (ESM) and advanced bundling techniques like tree shaking, the way we import and use libraries has changed significantly. This is where lodash-es comes into play.
Understanding the Differences
1. ES Module Support
lodash-es: This version of Lodash is designed to work with ES modules (ESM). It uses the nativeimportandexportsyntax, making it a better fit for modern JavaScript environments that support ES modules.lodash: The standard version of Lodash uses CommonJS module syntax, which is typical for Node.js environments but less optimal for modern front-end builds.
2. Tree Shaking
lodash-es: Supports tree shaking out of the box. Tree shaking is a technique used by modern JavaScript bundlers (like Webpack or Rollup) to eliminate unused code from the final bundle. By usinglodash-es, you can ensure that only the parts of Lodash you actually use are included in your build, potentially reducing your bundle size.lodash: While you can achieve some level of tree shaking withlodashby using tools likebabel-plugin-lodash, it requires additional configuration and might not be as effective as usinglodash-es.
3. Compatibility and Performance
lodash-es: Might be slightly better in performance for client-side applications due to the optimized module loading and tree shaking capabilities. It aligns better with modern JavaScript practices and tools.lodash: Is more commonly used in server-side environments where the benefits of tree shaking and ES module syntax are less impactful.
4. Tooling and Ecosystem
lodash-es: Works seamlessly with modern build tools that support ES modules, like Rollup and newer versions of Webpack.lodash: Has broader compatibility with older build systems and tools that expect CommonJS modules.
Practical Example: Migrating from lodash to lodash-es
Let’s walk through a practical example of migrating a project from lodash to lodash-es. Suppose we have a project that uses several Lodash functions.
Original Code with lodash
Here’s a sample code snippet using lodash:
const _ = require('lodash');
const array = [1, 2, 3, 4, 5];
const evens = _.filter(array, (num) => num % 2 === 0);
const doubled = _.map(evens, (num) => num * 2);
console.log(doubled); // Output: [4, 8]Migrated Code with lodash-es
First install with Typescript types:
Elebase USB to USB C Adapter for iPhone 17 4Pack,USBC Female to A Male Car Charger Adapter,Type C Converter Apple 16 Pro Max 15 14 Plus,iWatch Watch 11 10 Se Ultra 3,iPad Air,Samsung Galaxy S25,Black
$6.65 (as of November 28, 2025 01:44 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Metapen Pencil A8 for Apple iPad 2018-2025, (2X Faster Charge), Tilt Sensitivity, Pixel Precision, Stylus Pen for iPad 11/10/9/8/7/6th Gen, Pro 12.9/11/13-inch M4, Air 3/4/5/M2/M3, Mini 5/6th, White
$14.99 (as of November 28, 2025 01:44 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Enshittification: Why Everything Suddenly Got Worse and What to Do About It
$21.02 (as of November 26, 2025 18:35 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)npm install lodash-es
npm install --save-dev @types/lodash-esTo migrate this code to use lodash-es, we’ll update the imports to use ES modules:
import { filter, map } from 'lodash-es';
const array = [1, 2, 3, 4, 5];
const evens = filter(array, (num) => num % 2 === 0);
const doubled = map(evens, (num) => num * 2);
console.log(doubled); // Output: [4, 8]By making this change, we enable tree shaking, ensuring that only the filter and map functions are included in the final bundle. This reduces the bundle size and improves performance.
Conclusion
In modern JavaScript development, optimizing performance and efficiency is crucial. By choosing lodash-es over lodash, we can leverage ES modules and tree shaking to create leaner, faster applications. The seamless integration with modern build tools and alignment with current best practices make lodash-es the superior choice for many projects.
Switching to lodash-es is a straightforward process that can yield significant benefits in terms of bundle size and performance. As JavaScript continues to evolve, staying up-to-date with these optimizations helps ensure that our code remains efficient and maintainable.


