You installed a package through npm, the npm audit output looked clean, and you moved on.
Fast-forward six months. You pull down the latest changes, something in CI lights up, and now you need a clear answer about one dependency: is tslib actually a problem in this tree? Digging through the whole audit report for that one answer is busywork.
Modern npm can answer it more directly. You can query the dependency tree with a vulnerability selector, filter structured audit data with jq, or fall back on plain terminal tools when you only need a rough look. Then you can trace exactly why the package is installed at all.
Here are four ways to check a single npm package, in the order you should reach for them.
Note: the commands below were tested on npm 10.9.7 and npm 12.0.1. Selectors and output shapes do change between major npm releases, so run npm -v before you wire any of this into a script.
1. Query the Package Directly with npm query
npm query walks your installed dependency tree using CSS-style dependency selectors. Two of them do the work here: #tslib matches packages named tslib, and :vuln narrows the results to instances with a known advisory.
npm query '#tslib:vuln'
An empty array means npm found no instance of that package matching a known advisory in the tree and registry data it queried. A populated array means it did, and each entry carries detailed package and dependency-tree metadata plus a location field showing where that copy lives under node_modules.
That metadata dump is a lot of JSON for one question. Trim it with jq:
npm query '#tslib:vuln' | jq '.[] | {location, version, advisories: [.queryContext.advisories[] | {severity, title}]}'
The :vuln selector attaches every matching advisory to the node under queryContext.advisories, so you get severity, title, CVSS score, CWE, and the vulnerable version range without a second command – and you get all of them, not just the first.
You can filter by severity inside the selector, which helps when the tree is noisy:
npm query ':vuln([severity=high])'
One gotcha: severity filtering matches that exact severity and nothing above or below it. [severity=high] will not show you critical findings. Pass them as a list if you want both:
npm query ':vuln([severity=critical],[severity=high])'
Selectors compose, so you can scope the check to your production tree instead of reaching for a flag:
npm query '.prod#tslib:vuln' # this package, production tree only npm query '.prod:vuln' # everything vulnerable in the production tree
Two more things to know before you trust this in automation. :vuln and :outdated both reach out to the registry, so neither works offline. And the #name@version form you’ll still find in older documentation no longer parses – npm 12 rejects #[email protected] with an EQUERYNODEPTYPE error. Use the semver pseudo selector instead:
npm query '#tslib:semver(2.4.0)'
The :vuln selector landed in npm 10.5.0. If you’re not sure what you’re running, probe for it rather than guessing:
npm query ':vuln' >/dev/null 2>&1 && echo "supported" || echo "upgrade npm"
On anything older, skip to the jq method.
2. Filter npm audit JSON with jq
npm audit goes back to npm 6, while :vuln needs npm 10.5.0 or later. That makes audit JSON the safer choice for a shared repo where contributors may be on older npm releases.
npm audit --json | jq '.vulnerabilities["tslib"]'
The –json flag returns machine-readable audit data instead of a formatted table. On npm 7 and later, that report contains a vulnerabilities object keyed by package name, so the filter above pulls the entry for tslib directly. Get the fields that actually drive a decision:
npm audit --json | jq '.vulnerabilities["tslib"] | {severity, range, fixAvailable}'
Read the top-level range as the aggregate vulnerable range for that entry. Do not reach into .via[0].range to get it. The via array mixes advisory objects with bare package-name strings for vulnerabilities inherited through a parent, and even when via[0] happens to be an object it often carries a narrower range than the entry as a whole – on a test tree, express reported <4.20.0 from via[0] against an aggregate range of <=4.21.2 || 5.0.0-alpha.1 – 5.0.0. Silently wrong is worse than empty.
When you do want to separate direct advisories from inherited ones, ask for via explicitly and read it yourself:
npm audit --json | jq '.vulnerabilities["tslib"] | {severity, range, via, fixAvailable}'
Use bracket syntax rather than .vulnerabilities.tslib. It costs two characters and it’s the only form that survives a scoped package name, where dot notation breaks on the @ and the /:
npm audit --json | jq '.vulnerabilities["@babel/traverse"]'
To see everything flagged before going package by package:
npm audit --json | jq -r '.vulnerabilities | keys[]'
null Does Not Mean No Vulnerability
If the filter returns null, all you’ve learned is that the report has no entry under that key. Four different situations produce that same null:
- The installed version has no advisory in the data npm queried.
- The package is not part of the audited tree.
- The package was excluded from the audit, for example through –omit=dev.
- The package name was entered incorrectly.
Make the result say something instead of guessing:
npm audit --json | jq '.vulnerabilities["tslib"] // "no entry in audit report"'
Then confirm the package is actually installed, using the check in section 4.
If You’re Gating a Build on This
The exit code will mislead you. npm audit exits 1 whenever it finds any vulnerability at or above the configured audit level, anywhere in the tree – it says nothing about the package you asked about. Raising the threshold with –audit-level=high changes when the command fails; it does not remove lower-severity findings from the report, which stays identical either way.
npm query behaves better here: it exits 0 whether or not it finds anything, so you can gate on the result set itself.
if [ "$(npm query '#tslib:vuln' | jq length)" -gt 0 ]; then echo "vulnerable tslib present" fi
If you only care about what ships to production, run npm audit –omit=dev for the audit path, or use the .prod selector shown in section 1 for the query path. A critical finding in a build-only dependency is a different conversation than one in your runtime tree.
3. Quickly Search Human-Readable Output with grep
When you just want a rough look and don’t want to think about JSON, pipe the standard output into grep.
npm audit | grep -A 5 -i "tslib"
The | operator hands npm audit‘s standard output to grep, which scans it line by line. -A 5 prints five lines of trailing context after each match, which may capture the surrounding advisory details. -i makes the match case-insensitive.
This is fragile, and it’s worth being specific about why. Line wrapping, layout changes between npm releases, and advisory blocks longer than your context window can all hide the part you needed. Worse, a silent no-match is ambiguous in exactly the way null is – it might mean clean, or it might mean your pattern missed a wrapped line.
Fine for eyeballing. Never use it as evidence that a package has no known vulnerability.
4. Confirm Which Versions Are Actually Installed
An audit report describes the dependency tree npm resolves from your lockfile. By default npm audit requires a package-lock.json or shrinkwrap, submits the resolved package names and versions to the registry, and compares them against known advisories. It’ll even run with –package-lock-only and no node_modules directory at all.
npm ls inspects the installed tree under node_modules: npm ls tslib
The positional filter here does more than people expect. npm walks the whole tree and prints the path to every matching instance, nested copies included – so a package four levels deep still shows up. Adding –all does not change that output when you’re filtering by name (verified on npm 10 and npm 12); –all is what you want for an unfiltered npm ls, where the default view stops at direct dependencies.
Expect duplicates. A single project can easily carry three copies of the same package at different versions, and only some of them fall inside the vulnerable range.
Don’t Script Against the npm ls Exit Code
npm ls tslib exits 0 when it finds a match and 1 when it doesn’t, which looks like a clean presence check. It isn’t quite. If the matched package is itself flagged as invalid, extraneous, or missing, npm raises ELSPROBLEMS and exits 1 while still printing the package it found. An installed-but-mismatched dependency reads as “not installed”:
`– [email protected] invalid: “0.0.8” from the root project
npm error code ELSPROBLEMS
Unrelated problems elsewhere in the tree did not pollute the filtered exit code in testing, so this is narrower than it sounds – but it’s exactly the case you’re likely to hit while chasing a version mismatch. For scripts, count matches with npm query instead, which exits 0 regardless of tree health and finds nested copies too:
[ "$(npm query '#tslib' | jq length)" -gt 0 ] && echo "installed" || echo "not installed"
Reaching into npm ls –json for .dependencies[“tslib”] is a tempting alternative and a trap: transitive packages are nested under their parents, so a top-level lookup reports a package as absent when it’s sitting two levels down.
One more thing: the lockfile and node_modules drift apart constantly. After pulling changes, run npm ci before treating the local tree as authoritative.
Bonus: Find Out Why the Package Is Installed
When the flagged package isn’t in your own package.json, something else dragged it in. Run this from the project root:
npm explain tslib
npm explain prints the dependency chain for every matching installation, so each copy gets its own trace back to the root project. When several copies exist and you only care about one, pass its path:
npm explain node_modules/some-package/node_modules/tslib
That prints the chain for that single instance, including cases where two different parents both depend on the same intermediate package.
If it’s your direct dependency → bump it yourself. If a parent pins it → upgrade the parent, or add an overrides entry in package.json (npm 8.3+) as a stopgap. An override forces a version the parent was never tested against, so treat it as a change that needs your test suite behind it, not a one-line fix.
What npm audit Cannot Tell You
Treat all of this as baseline triage rather than an application-security program. None of these commands will:
- Determine whether your application can reach the vulnerable code path.
- Review your own source-code logic.
- Meaningfully analyze native binaries bundled inside a package.
- Detect a malicious or deliberately obfuscated package before someone reports it.
The first one matters most: the number of audit findings is not the number of exploitable vulnerabilities in your application. And every result depends on the tree npm resolved, the registry you’re configured against, and whatever advisory data existed at the moment you ran the command. Run the same audit next week and you may get a different answer with no change to your code.
Closing Thoughts
The short version, in the order to try it:
npm query '#tslib:vuln' # cleanest npm-native check npm audit --json | jq '.vulnerabilities["tslib"]' # portable, script-friendly npm ls tslib # what is actually installed npm explain tslib # why it's installed A one-time terminal check is a snapshot, and the value of dependency scanning comes from repetition. Continuous monitoring tooling – Dependabot, an open-source scanner like OSV-Scanner, or a commercial Software Composition Analysis platform – will surface newly disclosed advisories against code you haven't touched, keep findings visible across repos, and automate part of the upgrade work. What they won't do is escape the limits above: they still run mostly on known-vulnerability intelligence, and an unreported malicious package is invisible to them too.
Closing that particular gap means moving the check earlier than the advisory, which is the angle TuxCare SecureChain for OSS takes – it serves your npm dependencies from a curated registry where packages are rebuilt from source and screened before they ever land in your node_modules.
The terminal commands stay useful regardless. When you need an immediate answer about one package in one project, they’re faster than opening a dashboard.

