FG
💻 Software🛠️ Developer ToolsMicrosoft

[BUG] npx package@version uses incorrect installed version in npx 7

Fresh5 days ago
Mar 14, 20260 views
Confidence Score66%
66%

Problem

Current Behavior: running `npx @package@version` generate it with the current install version Expected Behavior: it should be generated with the given version Steps To Reproduce: ex. steps to reproduce the behavior: 1. run `npm i -g npm@latest` to install npm 7 2. run `npx @angular/cli@next new` 3. answer all questions of the angular cli, it doesn't matter what the answers are 4. it will install angular 11 (while next is 12) Environment: - OS: Windows 10 - Node: 14.16.1 - npm: 7.12.0 (working fine with 6.14.13)

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix npx Version Resolution in npm 7

Medium Risk

In npm 7, the behavior of npx has changed to prioritize the globally installed version of a package over the specified version in the command. This results in npx using the current installed version instead of the version explicitly requested, leading to discrepancies in package versions.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Clear npm Cache

    Clear the npm cache to ensure that no old or conflicting package versions are being referenced.

    bash
    npm cache clean --force
  2. 2

    Install Specific Version Locally

    Instead of relying on npx to fetch the package version, install the desired version of the package locally in a temporary directory. This ensures that the correct version is used.

    bash
    mkdir temp-project && cd temp-project && npm install @angular/cli@next
  3. 3

    Run Angular CLI from Local Node Modules

    Execute the Angular CLI from the local node_modules directory to ensure the correct version is used.

    bash
    npx ./node_modules/@angular/cli/bin/ng new
  4. 4

    Verify Installed Version

    After creating the new Angular project, verify that the installed version of Angular matches the specified version.

    bash
    cd <project-directory> && npm list @angular/core

Validation

Confirm that the installed version of Angular matches the expected version specified in the command. If it shows the correct version, the fix has worked.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsrelease-7.xrelease-8.xbugpriority-1