cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] misleading error: npm WARN config init.author.name Use `--init-author-name` instead.

Open coolaj86 opened this issue 3 years ago • 11 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 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 avatar Aug 08 '22 22:08 coolaj86

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

ljharb avatar Aug 08 '22 22:08 ljharb

Related to https://github.com/npm/cli/issues/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

coolaj86 avatar Aug 08 '22 22:08 coolaj86

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 https://github.com/npm/rfcs/pull/566 lands).

ljharb avatar Aug 08 '22 22:08 ljharb

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 avatar Aug 08 '22 22:08 coolaj86

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.

coolaj86 avatar Aug 08 '22 22:08 coolaj86

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 avatar Aug 08 '22 23:08 RamiSJ12

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

RamiSJ12 avatar Aug 08 '22 23:08 RamiSJ12

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.

ljharb avatar Aug 08 '22 23:08 ljharb

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

coolaj86 avatar Aug 08 '22 23:08 coolaj86

ah interesting

ljharb avatar Aug 09 '22 00:08 ljharb

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 avatar Aug 10 '22 15:08 wraithgar

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

wraithgar avatar Aug 11 '22 20:08 wraithgar