cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] when installing npm npm.ps1 is generated, ps1 files don't handle -- as expected!

Open AnderssonPeter opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

If I run npm run test -- --value '10' the npm.ps1 file removes the -- this in turn removes all parameters that start with --.

 > npm run test -- --value '10'

> [email protected] test
> node test.js "10"

if I remove npm.ps1 powershell instead executes npm.cmd and everything works as expected.

npm run test -- --value '10'

> [email protected] test
> node test.js "--value" "10"

I am using PowerShell 7.2.3

The only workaround besides deleting npm.ps1 is to add quotes around the --.

Expected Behavior

The -- should be passed to npm so that argument parsing works as intended.

Steps To Reproduce

  1. Install node
  2. Upgrade to latest npm with npm install -g npm
  3. Ensure that you have a npm script named test that runs a node file example "test": "node test.js".
  4. Run 'npm run test -- --value '10'`
  5. See error...

Environment

  • npm: 8.10.0
  • Node.js: 18.1.0 or 16.15.0
  • OS Name: Windows 10
  • System Model Name: ???
  • npm config:
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.1.0
; npm local prefix = T:\eslint-issue
; npm version = 8.10.0
; cwd = T:\eslint-issue
; HOME = D:\Users\Peter
; Run `npm config ls -l` to show all defaults.```

AnderssonPeter avatar May 16 '22 14:05 AnderssonPeter

See also:

  • https://stackoverflow.com/questions/72259748/scripts-arguments-starting-with-are-removed/72260631#72260631
  • https://stackoverflow.com/questions/70090402/why-arent-npm-scripts-relaying-arguments-correctly-on-windows-powershell
  • https://github.com/MicrosoftDocs/PowerShell-Docs/issues/8817

CherryDT avatar May 16 '22 14:05 CherryDT