Skip to content

bug(pnpm): direct optionalDependencies in importers are marked as dev #11434

Open
vincntlaw/trivy
#1

Description

@nikpivkin

Discussed in #11427

In pnpm v9 lockfiles, packages from optionalDependencies of a project get Dev: true. The same happens to packages that are only reachable through them. Trivy skips dev dependencies by default, so these packages and their vulnerabilities are missing from scan results.

pnpm installs optional dependencies in production and skips only devDependencies.

$ pnpm list --prod
optional-demo@1.0.0 /app
│
│   optionalDependencies:
└── lodash@4.17.20

$ pnpm install --prod
optionalDependencies:
devDependencies: skipped

The v9 parser reads only dependencies and devDependencies from importers. Lockfile v6 is not affected because Trivy uses the dev flag of each package there.

Activity

  1. added theissue type on Oct 19, 2026
  2. added
    kind/bug
    on Oct 19, 2026
  3. Varshith-Kali commented on Oct 19, 2026

    @Varshith-Kali

    I can take this one. The v9 parser reads only dependencies and devDependencies from the importers section, so anything installed via optionalDependencies never gets seeded as a production dep and defaults to Dev=true downstream (along with everything only reachable through it). I will add optionalDependencies to the Importer type and mark those as production, with a fixture-based test. PR incoming.

  4. drawliin commented on Oct 19, 2026

    @drawliin
    Contributor

    @Varshith-Kali it's already solved #11428

  5. Varshith-Kali commented on Oct 19, 2026

    @Varshith-Kali

    Withdrawing my claim above: I missed that #11428 (opened Oct 17) already implements this exact fix for the v9 importer optionalDependencies parsing. No duplicate work from me, will leave this one to that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions