Skip to content

[BUG] npx uses local package when another version is requested #3776

@Maxim-Mazurok

Description

@Maxim-Mazurok

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have prettier-plugin-packagejson installed (which has [email protected] as a dependency)

And trying to run npx [email protected] because I want to use version 1.48, before this tragic PR was merged

But npx picks up version 1.51.0 which is in my local deps, and in PATH. But it's the wrong version.

Expected Behavior

npx should make sure that it's running version 1.48, as requested.

Steps To Reproduce

  1. Make sure sort-package-json is not installed globally (npm rm sort-package-json)
  2. Make sure it's not in PATH: which sort-package-json should not return anything
  3. Do npm init
  4. Add these two scripts in package.json:
    "z": "should be last",
    "a": "should be first"
    
  5. Do npm i prettier-plugin-packagejson
  6. Run npx [email protected]
  7. Observe scripts still not sorted, because 1.51 was used (cat package.json, see "z" will be still before "a")

Optional:

  1. Remove local deps: rm -rf ./node_modules/
  2. Run npx [email protected] again
  3. Observe scripts are now sorted because 1.48 was used (cat package.json, see "a" will be before "z")

Environment

  • OS: Ubuntu 20 (WSL)
  • Node: 16.7.0
  • npm: 7.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingDuplicateduplicate of another, existing issueRelease 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