Find duplicate packages in a lockfile
List every copy of a package in your tree with npm ls --all --parseable to find duplicates, then try npm dedupe. Applies to npm 10 and its lockfile.
A bundle is larger than it should be, and you suspect two versions of one library. npm ls with --all prints every copy, and --parseable prints plain paths you can read at a glance.
npm ls ms --all --parseable/home/dev/app
/home/dev/app/node_modules/ms
/home/dev/app/node_modules/legacy-lib/node_modules/msTwo paths for ms mean two installed copies: one at the top and one nested under legacy-lib. The first line is the project itself. The flags are listed in the npm ls docs.
Next, see whether npm can merge them:
npm dedupe --dry-runnpm dedupe collapses copies only when one version satisfies every range that asks for it. When ranges conflict, as with legacy-lib pinning an older ms, the duplicate stays until you upgrade or override that package.
Search the lockfile too: package-lock.json lists each nested copy under its own node_modules/... key. Bundlers can still end up with two copies when the same code arrives through different paths, so check the build output when size matters.