Why does Powershell require two `- -` when passing arguments to script

I’m hesitant to open a bug, as I think this is probably a PowerShell thing, rather than npm, but it’s a hard thing to google for as having “npm powershell arguments two” in the same search results in things about how to pass arguments to multiple commands and other such stuff :confused:

When I run a script in anything other than PowerShell, I have to add -- before any arguments I want passed to the actual script, as per the docs. However, in PowerShell (including pwsh) I have to use two --s (i.e -- --).

PowerShell:

PS C:\Users\G-Rath\workspace\projects-oss\project> npm run test --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest

PS C:\Users\G-Rath\workspace\projects-oss\project> npm run test -- --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest

PS C:\Users\G-Rath\workspace\projects-oss\project> npm run test -- -- --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest "--coverage"

WSL:

g-rath@CINDY:/c/Users/G-Rath/workspace/projects-oss/project$ npm run test --coverage

> my-project@0.0.0 test /c/Users/G-Rath/workspace/projects-oss/project
> jest

^C
g-rath@CINDY:/c/Users/G-Rath/workspace/projects-oss/project$ npm run test -- --coverage

> my-project@0.0.0 test /c/Users/G-Rath/workspace/projects-oss/project
> jest "--coverage"

^C
g-rath@CINDY:/c/Users/G-Rath/workspace/projects-oss/project$ npm run test -- -- --coverage

> my-project@0.0.0 test /c/Users/G-Rath/workspace/projects-oss/project
> jest "--" "--coverage"

^C

cmd:

C:\Users\G-Rath\workspace\projects-oss\project>npm run test --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest

Terminate batch job (Y/N)? y

C:\Users\G-Rath\workspace\projects-oss\project>npm run test -- --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest "--coverage"

Terminate batch job (Y/N)? y

C:\Users\G-Rath\workspace\projects-oss\project>npm run test -- -- --coverage

> my-project@0.0.0 test C:\Users\G-Rath\workspace\projects-oss\project
> jest "--" "--coverage"

Terminate batch job (Y/N)? y

My understanding of PowerShell is fairly limited, as I now typically use WSL, but can’t for some of my commands as this is an Electron project.

That’s meant to be

My understanding of PowerShell is fairly limited, as I now typically use mainly WSL, so I wouldn’t be surprised if this was a PowerShell “feature” rather than an npm bug.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.