Skip to content

[BUG] npm i splits command line arguments incorrectly #7684

@mwaibel-go

Description

@mwaibel-go

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When installing a package with a version range, npm installs the package 'undefined' because it parses the command line arguments wrong.

Expected Behavior

When installing a package with a version range, it should install the requested package at one of the requested versions, preferrably the lowest (IMHO), and not install the undefined package.

Steps To Reproduce

$ mkdir npm-repro
$ cd npm-repro
$ npm i typescript@">=2.0.0 <5.0.0" --verbose
npm i typescript@">=2.0.0 <5.0.0" --verbose
npm verbose cli /home/mwaibel/bin/node-v18.20.3-linux-x64/bin/node /home/mwaibel/bin/node-v18.20.3-linux-x64/bin/npm
npm info using npm@10.8.2
npm info using node@v18.20.3
npm verbose title npm i typescript@>=2.0.0 <5.0.0
npm verbose argv "i" "typescript@>=2.0.0" "<5.0.0" "--loglevel" "verbose"

Note in the line above: "i" "typescript@>=2.0.0" "<5.0.0" – the version ranges got separated.

npm verbose logfile logs-max:10 dir:/home/mwaibel/.npm/_logs/2024-07-24T15_01_15_655Z-
npm verbose logfile /home/mwaibel/.npm/_logs/2024-07-24T15_01_15_655Z-debug-0.log
npm http fetch GET 200 https://npm.global-office.de/undefined 97ms (cache revalidated)
npm http fetch GET 200 https://npm.global-office.de/typescript 811ms (cache updated)
npm http fetch GET 200 https://npm.global-office.de/undefined 27ms (cache updated)
npm warn deprecated undefined@0.1.0: this package has been deprecated
npm http fetch POST 200 https://npm.global-office.de/-/npm/v1/security/advisories/bulk 256ms
npm http fetch GET 200 https://npm.global-office.de/typescript/-/typescript-5.5.4.tgz 1112ms (cache miss)

added 2 packages, and audited 3 packages in 2s

found 0 vulnerabilities
npm verbose cwd /home/mwaibel/tmp/npm-repro
npm verbose os Linux 5.10.102.1-microsoft-standard-WSL2
npm verbose node v18.20.3
npm verbose npm  v10.8.2
npm verbose exit 0
npm info ok

Environment

  • npm: 10.8.2
  • Node.js: 10.20.3
  • OS Name: Ubuntu (uname -a: Linux MAX-LAPTOP 5.10.102.1-microsoft-standard-WSL2 archive: committable offline dependency archive #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions