40

I would like to publish my git repository to npm so I can use it in other projects. But when I run the npm publish command I get the following error:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/vue-toggle-component
npm ERR! 404
npm ERR! 404  'vue-toggle-component@0.1.0' 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! A complete log of this run can be found in:
npm ERR!     C:\Users\niels\AppData\Roaming\npm-cache\_logs\2020-10-29T10_47_26_952Z-debug.log

When trying to bugfix, I have tried the npm adduser command and the npm login command to make sure I logged in. Both of these did not solve my problem since it looked like I was already logged in.

My package.json:

{
  "name": "vue-toggle-component",
  "version": "0.1.0",
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.11"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "babel-eslint": "^10.1.0",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "vue-template-compiler": "^2.6.11"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "babel-eslint"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead"
  ],
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },
  "description": "## Project setup ``` yarn install ```",
  "main": "babel.config.js",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/nehlis/vue-toggle-component.git"
  },
  "keywords": [
    "Vue.js",
    "Toggle",
    "component",
    "Lightweight",
    "Checkbox"
  ],
  "author": "Niels Bosman",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/nehlis/vue-toggle-component/issues"
  },
  "homepage": "https://github.com/nehlis/vue-toggle-component#readme"
}

Does anyone know how to fix this?

Niels Bosman
  • 826
  • 1
  • 8
  • 19
  • What command did you used exactly ? Was it `npm publish ` ? – Hollyol Oct 29 '20 at 11:36
  • @Hollyol I just cd'd to the directory and ran `npm publish`. Nothing after that. – Niels Bosman Oct 29 '20 at 11:36
  • I share a [npm publish tutorial](https://hackernoon.com/how-to-publish-your-package-on-npm-7fc1f5aae600) and also, [a few answers from here](https://stackoverflow.com/questions/39115101/getting-404-when-attempting-to-publish-new-package-to-npm), but i can't help you further :/ – Hollyol Oct 29 '20 at 11:48
  • I think in my case it's because I didn't have permission to publish a new package in the given `@namespace` – Boris Verkhovskiy Oct 20 '21 at 20:31

8 Answers8

38

Try npm login. In case of npm publish, sometimes misleading message is shown.

Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
  • 1
    Even though this was not the accepted answer, this was the answer I needed. Don't forget to sign in via the CLI! Thank you! – Calvin Ellis Jul 28 '22 at 22:07
13

Based on the https://npm.pkg.github.com/ appearing in the error output, you are trying to publish to GitHub Packages and not the npm registry (which are still separate, although GitHub now owns npm). According to the GitHub packages docs:

GitHub Packages only supports scoped npm packages. Scoped packages have names with the format of @owner/name. Scoped packages always begin with an @ symbol. You may need to update the name in your package.json to use the scoped name. For example, "name": "@codertocat/hello-world-npm".

So you'll need to either change your configuration to point to the npm registry rather than the GitHub packages registry, or else change the name field in your package.json to be a scoped package name.

Trott
  • 66,479
  • 23
  • 173
  • 212
8

I have the same issue the problem comes from the published package is not accessible so you will need to add .npmrc with your private repo to be like this

registry=https://npm.pkg.github.com/yourcompany

or

@yourcompany:registry=https://npm.pkg.github.com
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
5

As another user mentioned you have to add yourself to the private registry of your company or organization. But if you don't have your .npmrc setup, this command will create the file automatically as well as update your registry:

npm config set registry https://registry.your-company-registry.npme.io/

However the most robust way is to simply do

npm login
Embedded_Mugs
  • 2,132
  • 3
  • 21
  • 33
1

I faced the same problem and used almost all the valid solutions that I felt If you published it on GitHub then this could be something that could help you. like

  • updating npm to the latest version
  • setting registry using npm config set registry https://registry.your-company-registry.npme.io/
  • resetting token

It still didn't work

If you have uppercase characters in your GitHub username, and if you are using the command provided by GitHub under the package section

Make sure to update your username when you run that command locally By default, GitHub does not show uppercase characters in the command under the packages section.

So if your user name is UserName123 and package name is my-first-package the command that GitHub will show is

npm install @username123/my-first-package@1.0.0

see that the username is case-sensitive when you install a package hence, update your command to

npm install @Username123/my-first-package@1.0.0

and hopefully it should work fine

Deepak
  • 49
  • 1
  • 5
0

In the .npmrc file add the below code

always-auth = true
@your_company:registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/
registry=https://npm.artifactory.your_company.com/artifactory/api/npm/npm/

In GIT bash execute command

npm config set registry https://registry.npmjs.org/
npm install
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Surya R Praveen
  • 3,393
  • 1
  • 24
  • 25
0

It's all about authentication.

Seems like username/password auth is no more working with npm publish.

You need to generate Access Token enter image description here

Then use it to publish

NPM_TOKEN=blahblahblahblaha npm publish
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
0

steps to publish correctly:

1.- set repository where you want to publish, you can change for you own registry server

npm config set registry https://registry.npmjs.org/

2.- login (need previus register in npm or your custom registry)

npm login

3.- go your package and set your scope

cd /your/package/path
npm init --scope=@my-org
#or
npm init --scope=@my-username

4.- finally publish your package

npm publish --access public

ref: https://docs.npmjs.com/creating-and-publishing-scoped-public-packages

Adán Escobar
  • 1,729
  • 9
  • 15