Niels Bosman
Niels Bosman

Reputation: 956

Package is not publishing to npm (not in the npm registry)

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  '[email protected]' 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?

Upvotes: 48

Views: 129053

Answers (10)

simlmx
simlmx

Reputation: 1333

I was missing the --scope argument when logging in, to push my scoped package:

npm login --scope @your-org

Then

npm publish --access public worked properly.

Upvotes: 0

Patrice Thimothee
Patrice Thimothee

Reputation: 977

If nothing works, you can delete your .npmrc file and try publishing again npm publish (after logging in with npm login).

(The local .npmrc has precedence, which might override the publishing functionalities).

You can put it back when the publish is successful.

Upvotes: 0

Adán Escobar
Adán Escobar

Reputation: 4793

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

Upvotes: 0

Deepak
Deepak

Reputation: 94

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

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

npm install @Username123/[email protected]

and hopefully it should work fine

Upvotes: 1

Surya R Praveen
Surya R Praveen

Reputation: 3745

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

Upvotes: 0

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93591

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

Upvotes: 2

Embedded_Mugs
Embedded_Mugs

Reputation: 2436

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

Upvotes: 6

Yuvraj Patil
Yuvraj Patil

Reputation: 8774

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

Upvotes: 40

Mina Fawzy
Mina Fawzy

Reputation: 21472

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

Upvotes: 10

Trott
Trott

Reputation: 70183

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.

Upvotes: 18

Related Questions