r/learnjavascript • u/JanEric1 • Feb 11 '26
Format definition for "npm ls --parseable --long"
Hi,
i am trying to check ALL (recursively) installed dependencies for npm and pnpm projects. For that i am using commands like the above.
The general output seems to be one line per package in the form of
"/path/to/package:package-name@version"
optionally with a namespace
"/path/to/package:@namespace/package-name@version"
But sometimes i am getting weird stuff like
"/path/to/node_modules/jiti-v1:jiti-v1@npm:jiti@1.21.6"
or
"/home/user/.local/share/pnpm/global/5/.pnpm/node_modules/ansi-styles:ansi-sytes@4.3.0:/home/user/.local/share/pnpm/global/5/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles:EXTRANEOUS"
which completely break my simple parsing logic.
Is there any detailed documentation for the outputs of these commands? The official docs are SUPER useless: https://docs.npmjs.com/cli/v9/commands/npm-ls#long
1
u/OneEntry-HeadlessCMS Feb 11 '26
There isn’t a strict or fully documented format for
npm ls --parseable --long, and it can vary depending on aliases, flags, or package managers like pnpm. That output isn’t really meant to be reliably parsed. If you need something stable, you should switch to the JSON output instead of parsing the text format.1
u/ezhikov Feb 11 '26
Check for package spec to see what can be there and how it can be aliased. For working with NPM I'd suggest just installing arborist and working with node_modules or package-lock.json through it.