Docs / Getting started / Installation

Installing Lodash with npm

Lodash is published as a single package with per-method modules. This page walks through installing it, confirming the installed version, and importing only what your build actually needs.

Updated 12 October 2026 · 4 min read · applies to lodash@4.17.x

1. Install the package

From the root of a project that already has a package.json, run one of the following. Pick the one that matches the lockfile already in your repository — mixing package managers in one project is the usual cause of "works on my machine" dependency trees.

npm install lodash
No project yet? Create one first with npm init -y, then install. Without a package.json, npm will still install into node_modules but will not record the dependency for anyone else.

2. Verify the installation

Print the resolved version straight from the installed package. This reads the module you actually got, not the version string in your manifest:

node -e "console.log(require('lodash').VERSION)"

You should see something in the 4.17.x range. If you see undefined, the require resolved something that is not lodash — usually a stale global install shadowing the local one.

3. Import only what you need

The root import pulls in the whole library. Per-method imports keep unused functions out of the bundle:

// whole library — convenient, largest bundle
import _ from 'lodash';

// one method — smallest bundle, works with every bundler
import debounce from 'lodash/debounce';

For ESM-only toolchains, install lodash-es instead and import from the package root. It ships the same functions as ES modules and is tree-shakeable without per-method paths.

4. Check what you shipped

If your bundle grew by more than a few kilobytes after adding lodash, a root import is almost always the reason. Run your bundler's analyser before and after the change and compare the lodash slice of the graph.

Frequently asked questions

The CommonJS build does, through your bundler's interop. For native ESM in Node, use lodash-es or per-method paths. Node's own loader cannot import the CJS entry by named export.

Usually a second file still imports the root, or a dependency does. Search the built output for the string lodash.min and check the module graph for a single large lodash chunk — one root import is enough to pull everything back in.

The preview renders the buffer, not the finished file: it shows exactly what has been inserted so far. The remaining lines are recorded as an ordered plan and are inserted on demand, which is why the line numbers can jump between files in a multi-file answer.

Show the full step-by-step guide for this session

No walkthrough planned yet.

Yes, with a <script> tag pointing at the UMD build. You then get a global _. This is not recommended for new code — it defeats tree shaking and costs the full library on every page load.