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

[TOO MANY TANGENTS] [BUG] misleading error: npm WARN config init.author.name Use --init-author-name instead. #5279

Closed
2 tasks done
coolaj86 opened this issue Aug 8, 2022 · 12 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@coolaj86
Copy link

coolaj86 commented Aug 8, 2022

Updated

See #5302.

The discussion went in unhelpful directions. #5302 replaces this issue.

Original

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

If I run the config command to set my name, I get a confusing and misleading warning:

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

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

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="[email protected]"

These are all ignored on npm init.

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

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

Steps To Reproduce

As shown above.

Environment

  • npm: 8.11.0
  • Node.js: v16.16.0
  • OS Name: macOS
  • System Model Name:
  • npm config:
; N/A
@coolaj86 coolaj86 added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Aug 8, 2022
@ljharb
Copy link
Contributor

ljharb commented Aug 8, 2022

fwiw, in my $HOME/.npmrc, i have init-author-name = My Name.

@coolaj86
Copy link
Author

coolaj86 commented Aug 8, 2022

Related to #4840

Workaround

It appears that the desired behavior is to

  • switch from using // as a comment to ;
  • switch from npm config set foo.bar.baz to npm config set foo-bar-baz (no -- prefix)
npm config set init-author-name "Your Name"
npm config set init-author-email "[email protected]"
npm config set init-author-url "https://yourblog.com"

npm config set init-version "1.0.0"
npm config set init-license "SEE LICENSE IN LICENSE"

npm config set scripts-prepend-node-path true

(I've also updated Getting Started with NPM (as a developer) with the new syntax)

Migrating from earlier versions

# Author Info

npm config set init-author-name "$(
    npm config get init.author.name
)"
npm config delete init.author.name

npm config set init-author-email "$(
    npm config get init.author.email
)"
npm config delete init.author.email

npm config set init-author-url "$(
    npm config get init.author.url
)"
npm config delete init.author.url

# Package Defaults

npm config set init-version "$(
    npm config get init.version
)"
npm config delete init.version

npm config set init-license "$(
    npm config get init.license
)"
npm config delete init.license

@ljharb
Copy link
Contributor

ljharb commented Aug 8, 2022

It's ini, so afaik ; is the only valid comment character.

As for the dots, init.author.name and init-author-name are distinct - the dots imply nesting, but it's necessarily a top-level config item (until npm/rfcs#566 lands).

@coolaj86
Copy link
Author

coolaj86 commented Aug 8, 2022

Couldn't this be Auto-Migrated?

Is there a material reason this be duplicated automatically and then ignored (unless different) for compatibility with previous versions?

  1. Valid, no warning:
    init.author.name="Your Name"
    init-author-name="Your Name"
  2. New versions on npm should update BOTH styles (for multi-node/npm compat)
    npm config set init.author.name "Your Name"
    Notice: new versions of npm use the format `init-author-name`
    npm config set init-author-name="Your Name"
  3. Invalid, generate warning
    init.author.name="Your Old Name"
    init-author-name="Your New Name"
    You have updated `init.author.name` with an old version of npm, which is in conflict with the new version:
        init.author.name="Your Old Name"
        init-author-name="Your New Name"   
    Update both to "Your New Name" [Y/n]?

@coolaj86
Copy link
Author

coolaj86 commented Aug 8, 2022

Off Topic: Comment Syntax

It's ini, so afaik ; is the only valid comment character.

Historically it's been //.
Also, //= has some special meaning (I think it's for preserving empty comments so that they don't get collapsed into a single comment),
and the special comment //registry.npmjs.org/:_authToken= is used for auth.

There's also @my-foo-namespace:my-foo-option= for config that applies to alternate (including paid) registries.

I come from the node v0.2 days and my .npmrc has been updated but never deleted/re-created from scratch, so there's a variety of cruft in there, none of which generated warnings until quite recently - well, except that one time all the credentials had to be regenerated and actually use tokens instead of (hashed?) creds.

follow up

Yeah, any duplicate // or //= get stripped any time npm config set foo "bar" is run.

Any line starting with ; or # is completely stripped away entirely. // ...= must be used for comments you wish to keep.

// a comment I wish to keep =

An abuse of the quasi-ini syntax, no doubt.

@RamiSJ12
Copy link

RamiSJ12 commented Aug 8, 2022

Update npm with the command npm i -g npm. Run command npm cache verify and then run npm i.

Delete node_modules folder and package-JSON then run npm i.

@RamiSJ12
Copy link

RamiSJ12 commented Aug 8, 2022

$ npm cache clean --force
$ rm -rf node_modules
npm install
npm start

@ljharb
Copy link
Contributor

ljharb commented Aug 8, 2022

Yeah I’m pretty sure that’s not a comment, that’s a key named that, including the slashes.

npm is likely stripping all keys it doesn’t understand, which includes those non-comments.

@coolaj86
Copy link
Author

coolaj86 commented Aug 8, 2022

Off Topic: Comment Syntax

npm is likely stripping all keys it doesn’t understand, which includes those non-comments.

No, it preserves them. The known comments are stripped.

Before npm config

.npmrc:

; I will be deleted
# I will also be deleted
// I will live forever, in your heart =

After npm config

npm config set scripts-prepend-node-path true

.npmrc:

// I will live forever, in your heart=
scripts-prepend-node-path=true

@ljharb
Copy link
Contributor

ljharb commented Aug 9, 2022

ah interesting

@wraithgar
Copy link
Member

I'm having trouble following this issue. Is there a dot-separated entry in your npmrc? If so that will always cause this warning to happen. Removing it/updating it to the hyphen-separated version will fix this.

Additionally // has never been a comment in ini format. Only ; and # are ever mentioned. There is no parser I could find that uses // for comments, no mention of it on the wikipedia page for the format, nor any in the parser listed on that page. npm uses ini for parsing the npmrc file, and it does not support // for comments. That is a prefix we use in actual config items.

@wraithgar
Copy link
Member

It doesn't appear there's an actual bug here, npm is working as expected.

@coolaj86 coolaj86 changed the title [BUG] misleading error: npm WARN config init.author.name Use --init-author-name instead. [TOO MANY TANGENTS] [BUG] misleading error: npm WARN config init.author.name Use --init-author-name instead. Aug 11, 2022
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 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

4 participants