npm / cli

the package manager for JavaScript

Home Page:https://docs.npmjs.com/cli/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] When invoked from PowerShell prompt on Windows, positional arguments are not properly passed to NPM scripts

noseratio opened this issue · comments

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

process.argv is missing CLI arguments.

Using Node.js v22.0.0, NPM v10.6.0 and PowerShell v7.4.2 on Windows 11.

package.js:

{
  "name": "cli-test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  }
}

index.js:

console.dir(process.argv);

Running it from a PowerShell prompt:

PS C:\temp\cli-test> npm start -- command --arg=value

> cli-test@1.0.0 start
> node index.js command

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\temp\\cli-test\\index.js',
  'command'
]

Note how --arg=value is missing from process.argv.

Expected Behavior

--arg=value must be present in process.argv. It works properly if invoked from cmd (rather than PowerShell):

PS C:\temp\cli-test> cmd
Microsoft Windows [Version 10.0.22631.3527]
(c) Microsoft Corporation. All rights reserved.

C:\temp\cli-test>npm start -- command --arg=value

> cli-test@1.0.0 start
> node index.js command --arg=value

[
  'C:\\Program Files\\nodejs\\node.exe',
  'C:\\temp\\cli-test\\index.js',
  'command',
  '--arg=value'
]

It also works as expected under previous versions of Node v21.7.3 and NPM v10.5.0 and the same version of PowerShell v7.4.2.

Steps To Reproduce

See above in "Current Behavior".

Environment

  • npm: 10.6.0
  • Node.js: 22.0.0
  • OS Name: Windows 11 23H2 Build 22631.3527
  • System Model Name:
  • npm config:
; "builtin" config from C:\Users\User\AppData\Roaming\npm\node_modules\npm\npmrc

prefix = "C:\\Users\\User\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v22.0.0
; npm local prefix = C:\temp\cli-test
; npm version = 10.6.0
; cwd = C:\temp\cli-test
; HOME = C:\Users\User
; Run `npm config ls -l` to show all defaults.
commented

Duplicate of #7375