118

I just created a new package.

I'm now trying to publish it to NPM for the first time like this:

    ole@MKI:~/Sandbox/pli$ npm publish  --access public
    npm ERR! publish Failed PUT 404
    npm ERR! Linux 3.13.0-93-generic
    npm ERR! argv "/home/ole/.nvm/versions/v6.4.0/bin/node" "/home/ole/.nvm/versions/v6.4.0/bin/npm" "publish" "--access" "public"
    npm ERR! node v6.4.0
    npm ERR! npm  v3.10.3
    npm ERR! code E404

    npm ERR! 404 Not found : @supericium/pli
    npm ERR! 404 
    npm ERR! 404  '@supericium/pli' is not in the npm registry.
    npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
    npm ERR! 404 
    npm ERR! 404 Note that you can also install from a
    npm ERR! 404 tarball, folder, http url, or git url.

    npm ERR! Please include the following file with any support request:
    npm ERR!     /home/ole/Sandbox/pli/npm-debug.log

I tried updating both NodeJS and NPM to make sure that I have the latest version, which are:

ole@MKI:~/Sandbox/pli$ node --version
v6.4.0
ole@MKI:~/Sandbox/pli$ npm --version
3.10.3

Thoughts?

Ole
  • 41,793
  • 59
  • 191
  • 359
  • 3
    Yes, it makes no sense. Can't create a package because it doesn't exist. None of these answers solve the problem. – Steve Sep 28 '21 at 01:53
  • 1
    @Distortum Try running `publish` in verbose mode - in a very frustrating way, in normal mode many issues end up as 404 while the real reason may be 403 because of a variety of issues. Usually running the verbose mode makes the issue apparent. – Oleg Valter is with Ukraine Sep 28 '21 at 01:58

20 Answers20

125

You need to have registered "supericium" (npm adduser) as a username at the registry and be logged in (npm login) to publish under that scope.

Kevin Danikowski
  • 4,620
  • 6
  • 41
  • 75
Stoffe
  • 2,744
  • 2
  • 25
  • 24
62

It's solved by npm login in my case, the error message is misleading

igonejack
  • 2,366
  • 20
  • 29
  • It works... but when I published my package to **npm** their website stopped to work and shows me `error loading page` :))) – DenisKolodin Jan 16 '21 at 12:37
  • 1
    Sidenote: The problem isn't the client but that the npm registry sends 404. I've been told that when you e.g. use verdaccio as a proxy, it sends 401 if the login info is incorrect. Which makes the client show the expected "you need to log in" message. – AndyO May 09 '21 at 22:39
  • 3
    It doesn't work. – Steve Sep 28 '21 at 01:52
23

Came across this same error, and my issue was that the package was somehow set to "Read" access only. So I have to go to the NPM and update the package to "Read/Write" access:

1.

enter image description here

2.

enter image description here

Jee Mok
  • 6,157
  • 8
  • 47
  • 80
13

Nothing worked for me, except logging in again:

npm login

Hope this helps me or someone else in the future!

Omar Dulaimi
  • 846
  • 10
  • 30
9

You could also get this error when you change your password to NPM but you do not logout/login via your CLI. Using npm logout and then npm login worked for me.

Klemen
  • 91
  • 1
  • 1
6

in my case I had to verify the email address. even when npm whoami was telling me I was logged in fine.

dcsan
  • 11,333
  • 15
  • 77
  • 118
4

In my case, I was missing the repository field in the package.json of my new package that I was trying to publish.

"repository": "git://github.com/your-org/your-repo-name.git"

https://docs.npmjs.com/files/package.json#repository

Janno Teelem
  • 324
  • 2
  • 6
4

In my case, I got this message because the token that I was using had been revoked. I fixed it by:

  1. Generating a new access token in my npm account.
  2. Modifying the line: export NPM_TOKEN="<token>" in my .zshrc (or .bashrc) file
  3. Entering source ~/.zshrc in the terminal.
dmc85
  • 250
  • 1
  • 9
4

I just logged in to npm by using npm adduser command and it worked fine.

ASANIAN
  • 372
  • 2
  • 8
  • 1
    Whoa! This was the answer for me. Despite being authenticated via command line I had to re-add my user and retry the publish. Really bad CLI experience on that one. – Ben Racicot Oct 26 '21 at 13:54
3

This error appeared for me in two cases:

  1. When I wasn't logged in. You can check whether you are logged in or not by npm whoami, then if not logged in npm login.

  2. When I didn't have right to publish to the repository. In this case make sure you are added to the organization which owns the repo.

mpro
  • 14,302
  • 5
  • 28
  • 43
1

in my case i noticed that my npm account username in npm website is different than my npm normal user name. When i try to publish in console by login with normal username gave me this error.

publish Failed PUT 404 npm ERR! code E404 npm ERR! 404 User not found

But after login to console with account name it has published successfully

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35
1

Once you successfully publish the package you may experience when you try to npm install:

npm ERR! code E404
npm ERR! 404 Not Found: @xxx/yyy@latest

or something similar, regardless if you npm publish was successful. In this case make sure your {main: 'file.js'} in packages.json is there.

Ideally, you can call it index.js if you wish to leech directly from the package so you don't get things like import * from '@xxx/yyy/file'.

Greg Wozniak
  • 5,209
  • 3
  • 26
  • 29
1

In my case, I believe I enabled 2FA on npmjs.com so the publish token used in CD didn't work (should have thrown 401, but got 404).

Generating a new automation token on npmjs.com and updating the secret on my CD (GitHub actions) solved it.

Izhaki
  • 23,372
  • 9
  • 69
  • 107
0

I encountered the same problem but I successfully resolved it by uninstalling the LTS version, then installing Current version along with yarn.

0

Just adding my two cents to the possible solutions

I was getting this error in a CI workflow, so no interactive login or things related. Existing packages were working correctly, but adding a new one wasn't, I was getting a 404. I realized that it should be something related to the new package itself, not the CI environment, and it was.

The new package was missing two fields on its package.json, the repository and publishConfig fields.

Adding these two fields, it worked correctly (note that repository field is used in its expanded form, with the directory property)

"repository": {
  "type": "git",
  "url": "ssh://git@github.com/__user__/__repo-name__.git",
  "directory": "packages/__new-package-name__"
},
"publishConfig": {
  "registry": "https://npm.pkg.github.com/"
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Renato Rodrigues
  • 165
  • 1
  • 10
0

For me the fix seemed to be making a new "team" in the organisation and assigning myself and my package to this.

My guess is that my NPM organisation requires users to have 2FA on and two users assigned to the 'developers' group didn't have this on.

13twelve
  • 121
  • 5
0

publish to npm.pkg.github.com, this error stems from incorrect 'name' in package.json. name should be aligned to github scope. so : @

then you can go ahead and publish.

-1

In my case the problem was completely different.

I had to replace:

npm publish FOLDERNAME

with simply:

cd FOLDERNAME && npm publish

In my case I also had to manually specify the path of .npmrc using the --userconfig parameter:

cd myapp && npm publish -ddd --userconfig ../.npmrc
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
-2

In my case i accidentally typed https://registry.npmjs.org instead of https://registry.npmjs.com (.org vs .com)

Skylar Brown
  • 3,234
  • 2
  • 14
  • 7
  • 1
    The default in the docs lists `.org` as the correct URL - https://docs.npmjs.com/cli/v7/using-npm/config#registry – jthegedus Jul 21 '21 at 01:05
-3

In my case, I had a typo when passing the otp param:

// Wrong:
npm publish --access public --opt 123456

// Correct:
npm publish --access public --otp 123456
Matthew
  • 2,871
  • 5
  • 34
  • 59