np icon indicating copy to clipboard operation
np copied to clipboard

ERR 400 2FA when no 2fa is configured on account/repo

Open badluck13 opened this issue 5 years ago • 19 comments

There is an issue with the latest version 6.0.0 of np after the package is published it tries to do 2fa and it fails. The account doesn't have 2fa enabled, as well as npm repo. Also, the package is published and then it tries to do 2fa, that seems strange I would expect 2fa is a step before publishing.

Description

Commit Range:
v0.4.0...master

Registry:
https://registry.npmjs.org/

? Select semver increment or specify new version patch  0.4.1

  √ Prerequisite check
  √ Git
  ↓ Cleanup [skipped]
  √ Installing dependencies using npm
  √ Running tests using npm
  √ Bumping version using npm
  √ Publishing package using npm
  × Enabling two-factor authentication
    → npm ERR!     C:\Users\xxxxxxx\AppData\Roaming\npm-cache\_logs\2020-02-07T19_16_24_605Z-debug.log
    Pushing tags
    Creating release draft on GitHub

× Command failed with exit code 1: npm access 2fa-required serp-parser
npm ERR! code E400
npm ERR! 400 Bad Request - POST https://registry.npmjs.org/-/package/serp-parser/access

Here is the log file,

info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'access',
1 verbose cli   '2fa-required',
1 verbose cli   'serp-parser'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session d2ee52f34a8efa00
5 http fetch POST 400 a 372ms
6 verbose stack Error: 400 Bad Request - POST https://registry.npmjs.org/-/package/serp-parser/access
6 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-fetch\check-response.js:104:15
6 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:93:5)
7 verbose statusCode 400
8 verbose pkgid serp-parser@latest
9 verbose cwd C:\GitHub\serp-parser
10 verbose Windows_NT 10.0.18363
11 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "access" "2fa-required" "serp-parser"
12 verbose node v12.13.0
13 verbose npm  v6.12.0
14 error code E400
15 error 400 Bad Request - POST https://registry.npmjs.org/-/package/serp-parser/access
16 verbose exit [ 1, true ]

Expected behavior

I expect for the script to not try to enable 2fa as there is no configuration for it, and to finish everything up as a previous np v5.x.x

Environment

np - 6.0.0 Node.js - 12.13.x npm - 6.12.x Git - x.x.x OS - WIN10

badluck13 avatar Feb 08 '20 00:02 badluck13

Why it is not possible to make this 2fa-required optional? Should be enabled by default if npm has a bug it doesn't work

larsroettig avatar Feb 09 '20 22:02 larsroettig

See: https://github.com/npm/cli/issues/650

sindresorhus avatar Feb 13 '20 10:02 sindresorhus

Also, the package is published and then it tries to do 2fa, that seems strange I would expect 2fa is a step before publishing.

It's so that it can handle when you first publish a new package as you cannot enable 2FA on a package before it's published. Was just easier to have the same logic for both existing and new packages.

sindresorhus avatar Feb 13 '20 10:02 sindresorhus

Hey there,

Recently published a new package too and encountered the same issue. Because the 2FA step fails and exits, the push to Github isn't happening.

For now I'm pushing manually.

Weirdly enough, I've been using np before and never had this issue, so I don't fully understand what is happening 😄

peduarte avatar Feb 13 '20 16:02 peduarte

I just downgraded to 5.2.1 because this is broken. Let me know when it's fixed. That said, thanks for the wonderful work!

collincusce avatar Feb 17 '20 16:02 collincusce

I'm having the same issue with v6, downgrading works. It would be nice to have the flag to skip 2fa until the issue with npm cli is solved.

gabdara avatar Feb 18 '20 11:02 gabdara

Encountering the same issue. But downgrading to 5.2.1 works. Despite this, np is still a lifesaver!

gavinmcfarland avatar Mar 09 '20 18:03 gavinmcfarland

This is odd, I just had this issue but I am already using v5.2.1... What is happening?

papb avatar Mar 15 '20 17:03 papb

For now I am using @pixelastic's fork from #515, it's working perfectly for me.

  • npm i -D https://github.com/pixelastic/np/tarball/c3ab2e3b053c7da0ce40a572ca1616273ac080f8

  • package.json:

    {
      "scripts": {
        "release": "np --no-2fa"
      }
    }
    
  • npm run release

papb avatar Mar 15 '20 18:03 papb

Downgrading to 5.2.1 didn't work for me. npm/cli#650 is for npm access 2fa-required returning an error but that command works OK for me and doesn't throw.

Could there be something else failing too? np still fails for me on 2fa-required.

nerdyman avatar Mar 16 '20 00:03 nerdyman

@nerdyman Can you try my last suggestion just out of curiosity?

papb avatar Mar 16 '20 12:03 papb

Same problem here with 6.10.2 on OS X

I'm having the same issues with a public package, for which 2fa is intentionally off.

np fails with the following error (though the package is published anyway):

$ np patch
Publish a new version of pkg (current: 1.0.2)

  ✔ Prerequisite check
  ✔ Git
  ↓ Cleanup [skipped]
  ✔ Installing dependencies using npm
  ✔ Running tests using npm
  ✔ Bumping version using npm
  ✔ Publishing package using npm
  ✖ Enabling two-factor authentication
    → npm ERR!     /Users/me/.npm/_logs/2020-03-23T05_27_47_209Z-debug.log
    Pushing tags
    Creating release draft on GitHub

✖ Command failed with exit code 1: npm access 2fa-required pkg
npm ERR! code E400
npm ERR! 400 Bad Request - POST https://registry.npmjs.org/-/package/pkg/access

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2020-03-23T05_27_47_209Z-debug.log

dhowe avatar Mar 23 '20 05:03 dhowe

@dhowe Can you try my last suggestion just out of curiosity?

papb avatar Mar 23 '20 14:03 papb

Yes I am using that solution now -- works well, thanks

dhowe avatar Mar 24 '20 09:03 dhowe

I also had to downgrade to 5.2.1 to publish a new package because I couldn't get around this. Any chance you could just support the flag from the optional branch posted above? This is clearly a pretty big inconvenience for a lot of people.

gargrave avatar Mar 28 '20 19:03 gargrave

Thanks @papb, that solution worked for me, I used npx for it rather than editing my current set up.

npx https://github.com/pixelastic/np/tarball/c3ab2e3b053c7da0ce40a572ca1616273ac080f8 --no-2fa

It would be really good to get this officially resolved though, doing package releases via random tarballs makes me feel dirty.

nerdyman avatar Mar 31 '20 20:03 nerdyman

2020-07-18T07_38_21_727Z-debug.log

This is still happening. And bug #427 references this issue as well.

techhead avatar Jul 18 '20 07:07 techhead

No need to downgrade or install other forks.... I have version 6.5.0 and there is support to the --no-2fa tag

image

LukeSavefrogs avatar Oct 19 '20 13:10 LukeSavefrogs

The actual --no-2fa support version seems to be 6.4:

https://github.com/sindresorhus/np/releases/tag/v6.4.0

I think we can close this issue!

cloud-walker avatar Oct 19 '20 14:10 cloud-walker