Skip to content

[BUG] npm exec doesn't honor package version #3667

@jcayzac

Description

@jcayzac

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

npm x -q --yes --package=<package>@<version> -- <command> doesn't honor <version>, uses incompatible package that is locally available instead.

Expected Behavior

npm x -q --yes --package=<package>@<version> -- <command> honors <version>, does not uses incompatible package that is locally available instead.

Steps To Reproduce

  1. Write this package.json:
    {
      "private": true,
      "devDependencies": {
        "pnpm": "=6.12.1"
      }
    }
  2. Run npm i
  3. [email protected] is now installed locally.
    $ npm x  -q --yes -- pnpm --version
    6.12.1
  4. Run pnpm 6.13.0 now: npm x won't honor the version
    $ npm x -q --yes --package="[email protected]" -- pnpm --version
    6.12.1

The docs for npm exec state:

Package names provided without a specifier will be matched with whatever version exists in the local project. Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency.

Environment

  • OS: macOS 11.4
  • Node: 16.5.0
  • npm: 7.21.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 7.xwork is associated with a specific npm 7 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions