Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm config silently ignores values that start with a dash #2250

Closed
gizero opened this issue Nov 27, 2020 · 3 comments
Closed

[BUG] npm config silently ignores values that start with a dash #2250

gizero opened this issue Nov 27, 2020 · 3 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@gizero
Copy link

gizero commented Nov 27, 2020

Current Behavior:

Given a config command like this:

npm config set '//gitlab.vendor.com/api/v4/packages/npm/:_authToken' "-iF_9eLYJkB2a3simuB1"

It silently fails to set the configuration key. The command returns 0 while the key turns out to be empty in .npmrc.
My suspect is that -iF_9eLYJkB2a3simuB1 ends up being considered a command line option instead of a positional argument. This is somewhat confirmed by explicitly using -- to tell npm not to search for more options, which brings the expected behaviour back. Another workaround is to use the (apparently undocumented) syntax:

npm config set "//gitlab.vendor.com/api/v4/packages/npm/:_authToken=-iF_9eLYJkB2a3simuB1"

Still, IMO, silently ignoring the value is not the correct behaviour. We should probably at least complain about an invalid option instead.

Expected Behavior:

Either the configuration key is correctly assigned the given value, or the command fails due to an invalid -iF_9eLYJkB2a3simuB1 option.

Steps To Reproduce:

ex. steps to reproduce the behavior:

  1. with npm v6, v7, or latest
  2. run npm config set '//gitlab.vendor.com/api/v4/packages/npm/:_authToken' "-iF_9eLYJkB2a3simuB1"
  3. check your .npmrc content for the above key and verify it's empty:
    //gitlab.vendor.com/api/v4/packages/npm/:_authToken=
@gizero gizero added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 27, 2020
@gizero
Copy link
Author

gizero commented Nov 27, 2020

Very likely related to what this nopt very old issue is pointing out...

@isaacs
Copy link
Contributor

isaacs commented Dec 11, 2020

Use -- to prevent npm from parsing flags and switches on the command line. Not likely to be fixed any time soon, since a lot of code out in the wild depends on npm <some command> --my-custom-thing=whatever

@isaacs isaacs closed this as completed Dec 11, 2020
@isaacs
Copy link
Contributor

isaacs commented Dec 11, 2020

npm config set -- '//gitlab.vendor.com/api/v4/packages/npm/:_authToken' "-iF_9eLYJkB2a3simuB1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

2 participants