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] misleading error: npm WARN config init.author.name Use --init-author-name instead. #5302

Closed
2 tasks done
coolaj86 opened this issue Aug 11, 2022 · 2 comments
Closed
2 tasks done

Comments

@coolaj86
Copy link

coolaj86 commented Aug 11, 2022

Is there an existing issue for this?

  • I have searched the existing issues

#5279 was confusing due to tangential, unrelated discussion.

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior A

npm config set init.author.name "AJ ONeal"
npm WARN config init.author.name Use `--init-author-name` instead.

This is incorrect and/or silly.

  1. The error message is incorrect. --init-author-name is NOT a valid config option or flag
  2. It should print a deprecation notice AND do the correct behavior, or throw an actual error

Current Behavior B

npm config set --init-author-name "AJ ONeal"

This is NOT correct. It writes an invalid value to .npmrc.

Expected Behavior

Either the built-in documentation should be updated to give the output the corresponds to the expected input

Or the parsing should change to allow the given output as input in some way

For example:

npm ERR breaking change: you must now use `npm config set init-author-name` instead of `npm config set init.author.name`.
[exit 1]

Or

npm WARN deprecated use of `npm config set init.author.name`. Use `npm config set init-author-name` instead.
[writes _correct_ version of option to .npmrc]
[exit 0]

Or

npm config --init-author-name "AJ ONeal"
✅ updated `.npmrc` with `init-author-name=AJ ONeal`.

Steps to Reproduce

If I run the config command to set my name:

mv ~/.npmrc ~/".npmrc.$(date '+%F_%H.%M.%S').bak"

npm config set init.author.name "AJ ONeal"

I get a confusing and misleading warning that gives incorrect / useless feedback:

npm WARN config init.author.name Use `--init-author-name` instead.

Either this feedback is incorrect, or the behavior of npm is incorrect.

  • --init-author-name is NOT a valid command line flag
  • --init-author-name is NOT a valid config file entry

So then if I try again a few different ways:

npm config set --init-author-name "AJ ONeal"

npm config --init-author-name "AJ ONeal"

I get usage errors:

npm ERR! code EUSAGE

And if I try the simplest form I can think of:

npm --init-author-name "AJ ONeal"

I get yet a different usage error:

npm <command>

Usage:

...

And I can try putting --init-author-name in .npmrc, but this also doesn't work:

--init-author-name="AJ ONeal"
--init-author-email="coolaj86@gmail.com"

These are all ignored on npm init.

Environment

  • npm: 8.11.0
  • Node.js: v16.16.0
  • OS Name: macOS
  • System Model Name:
  • npm config:
; N/A

Keywords

Keywords for the sake of SEO and people trying to search for this in the GitHub tool:

  • init.author.name
  • init-author-name
  • --init-author-name
  • init.author.email
  • init-author-email
  • --init-author-email
  • init.author.url
  • init-author-url
  • --init-author-url
  • init.license
  • init-license
  • --init-license
  • init.version
  • init-version
  • --init-version
@coolaj86
Copy link
Author

coolaj86 commented Aug 11, 2022

Clarifications

@wraithgar What's unclear / what questions do you have?

Workaround

For others encountering this bug, see #5279: Workaround (comment)

@wraithgar
Copy link
Member

npm's deprecation system is a string that is shown whenever a deprecated config item is seen. This is manifesting after npm config has already parsed and set the config item. The deprecation output shows the value as a param. If it were without then this "bug" would exist for all other use cases where the param is being set, and not in an .npmrc file. We also do this for production by suggesting --omit=dev instead. This is just how our deprecation warnings are formatted.

We're not likely to change this in npm 8 but I will add a suggestion to npm 9 that npm config simply refuse to set deprecated configs at all. npm/statusboard#535

huiyifyj added a commit to huiyifyj/dotfiles that referenced this issue Apr 3, 2023
* Update config fields for npm
  - Update my email address to `i@fengyj.cn`.
  - Use `init-license`(and others) instead of `init.license`(and others).
    Update above settings config fields to remove warnings.
  More to see:
  - npm/cli#5302
  - https://stackoverflow.com/questions/71914123/warning-in-npm-config-at-latest-version/72113809#72113809

* Update copyright author for LICENSE: Huiyi.FYJ => Feng.YJ.

* Switch the default branch from `master` to `main`, and update related URL links in README file.
  For refer to https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/

* Update copyright year to 2023 in README file.

* Add backup tsinghua TUNA mirror URL for flutter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants