繁体   English   中英

Package 未发布到 npm(不在 npm 注册表中)

[英]Package is not publishing to npm (not in the npm registry)

我想将我的 git 存储库发布到 npm 以便我可以在其他项目中使用它。 但是当我运行npm publish命令时,出现以下错误:

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

尝试修复错误时,我尝试了npm adduser命令和npm login命令以确保我已登录。这两个都没有解决我的问题,因为看起来我已经登录了。

我的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"
}

有谁知道如何解决这一问题?

试试npm login npm publish情况下,有时会显示误导性消息。

根据出现在错误输出中的https://npm.pkg.github.com/ ,您正在尝试发布到 GitHub 包而不是 npm 注册表(它们仍然是独立的,尽管 GitHub 现在拥有 npm)。 根据GitHub 包文档

GitHub Packages 仅支持作用域范围的 npm 包。 作用域包的名称格式为@owner/name。 作用域包总是以@ 符号开头。 您可能需要更新 package.json 中的名称以使用范围名称。 例如,“名称”:“@codertocat/hello-world-npm”。

因此,您需要更改配置以指向 npm 注册表而不是 GitHub 包注册表,或者将package.jsonname字段更改为作用域包名称。

我有同样的问题,该问题来自无法访问已发布的包,因此您需要将.npmrc添加到您的私人.npmrc中才能像这样

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

或者

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

正如另一位用户所提到的,您必须将自己添加到您公司或组织的私人注册表中。 但是,如果您没有 .npmrc 设置,此命令将自动创建文件并更新您的注册表:

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

然而,最健壮的方法是简单地做

npm login

在 .npmrc 文件中添加以下代码

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/

在 GIT bash 中执行命令

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

截屏在此处输入图片说明

在此处输入图片说明

这都是关于身份验证的。

似乎用户名/密码身份验证不再与npm publish一起使用。

您需要生成访问令牌在此处输入图片说明

然后用它来发布

NPM_TOKEN=blahblahblahblaha npm publish

对我来说,修复似乎是在组织中建立一个新的“团队”并将我自己和我的 package 分配给这个。

我的猜测是,我的 NPM 组织要求用户启用 2FA,而分配给“开发人员”组的两个用户没有启用此功能。

我遇到了同样的问题,并使用了几乎所有我认为有效的解决方案如果您在 GitHub 上发布了它,那么这可能会对您有所帮助。 喜欢

  • 更新 npm 到最新版本
  • 使用npm config set registry https://registry.your-company-registry.npme.io/
  • 重置令牌

还是不行

如果您的 GitHub 用户名中包含大写字符,并且您使用的是 GitHub 在 package 部分下提供的命令

确保在本地运行该命令时更新您的用户名默认情况下,GitHub 在包部分下的命令中不显示大写字符。

因此,如果您的用户名是UserName123并且 package 名称是my-first-package ,则 GitHub 将显示的命令是

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

安装 package 时看到用户名区分大小写,因此,将命令更新为

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

希望它能正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM