首页 > 解决方案 > 无法将 npm 包发布到 GitHub 包

问题描述

我正在尝试将 npm 包发布到 GitHub 包注册表。这是我的package.json文件和.npmrc文件

包.json

{
  "name": "@chathurabuddi/constants",
  "version": "1.0.0",
  "description": "All constants",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/chathurabuddi/contants.git"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },
  "keywords": [
    "chathurabuddi",
    "constants"
  ],
  "author": "chathurabuddi",
  "homepage": "http://chathurabuddi.lk",
  "license": "ISC"
}

.npmrc

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

但是当我尝试运行时npm publish,它给了我以下错误。

C:\Users\CHATHURA\IdeaProjects\constants>npm publish
npm notice
npm notice package: @chathurabuddi/constants@1.0.0
npm notice === Tarball Contents ===
npm notice 201B index.js
npm notice 437B package.json
npm notice 917B .github/workflows/npm-publish.yml
npm notice === Tarball Details ===
npm notice name:          @chathurabuddi/constants
npm notice version:       1.0.0
npm notice package size:  889 B
npm notice unpacked size: 1.6 kB
npm notice shasum:        bf9cefa335b89aa1bd3950a7f7d953259f891f40
npm notice integrity:     sha512-n1GLzxFtEaklV[...]d5u0bMDQXVHiQ==
npm notice total files:   3
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/@chathurabuddi%2fconstants - The expected resource was not found.
npm ERR! 404
npm ERR! 404  '@chathurabuddi/constants@1.0.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\CHATHURA\AppData\Roaming\npm-cache\_logs\2021-06-27T02_58_58_228Z-debug.log

请注意,我已经通过运行登录到 npm npm login -registry=https://npm.pkg.github.com。用于登录的个人访问令牌包括所需的所有权限repopackage:readpackage:write

我已经尝试了几篇帖子中建议的几种解决方案,但都没有奏效。

有谁知道这个问题的确切问题是什么?

标签: node.jsnpmnpm-publishgithub-package-registry

解决方案


您似乎拼错了存储库 URL。

"url": "git://github.com/chathurabuddi/contants.git"

应该改为

"url": "git://github.com/chathurabuddi/constants.git"

package.json.

[1] https://docs.github.com/en/actions/guides/publishing-nodejs-packages#publishing-packages-to-github-packages


推荐阅读