当我运行"npm publish"时,出现了404错误。

10

我正在尝试将一个包发布到npm仓库。但是当我输入命令npm publish时,会出现以下错误。

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.

> imojha@1.0.0 prepublish .
> npm run build


> imojha@1.0.0 build /home/suraj/Projects/bitandbang
> node build.js

npm notice 
npm notice   imojha@1.0.0
npm notice === Tarball Contents === 
npm notice 1.1kB LICENSE     
npm notice 3.6kB bin/output  
npm notice 233B  bin/card.js 
npm notice 996B  package.json
npm notice 293B  README.md   
npm notice === Tarball Details === 
npm notice name:          imojha                                  
npm notice version:       1.0.0                                   
npm notice package size:  2.3 kB                                  
npm notice unpacked size: 6.2 kB                                  
npm notice shasum:        bb283ae5fe8aed311771f369866c13e24f1eb937
npm notice integrity:     sha512-Nzc+Ysmf4RgSi[...]XoT+OGYHNHoSQ==
npm notice total files:   5                                       
npm notice 
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.registry.github.com/imojha
npm ERR! 404 
npm ERR! 404  'imojha@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!     /home/suraj/.npm/_logs/2020-10-24T14_54_01_996Z-debug.log

我已成功运行npm login。然后我执行npm publish

我已从GitHub克隆了此存储库并发布到npm。实际上是关于创建你自己名字的npx卡片,如npx用户名。 我正在做同样的事情。

我尝试给它一个不同的包名称,但无法成功。所以,有人能告诉我我做错了什么吗?这是package.json文件。

{
  "name": "suraj-ojha",
  "version": "1.0.0",
  "description": "A personal card for Suraj Ojha (@suraj)",
  "main": "/bin/card.js",
  "bin": {
    "bitandbang": "./bin/card.js"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:Suraez/npxcard.git"
  },
  "homepage": "https://bnb.im",
  "scripts": {
    "prepublish": "npm run build",
    "build": "node build.js",
    "dev": "npm run build && node ./bin/card.js",
    "lint": "standard",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "card",
    "npm",
    "npm card",
    "npx",
    "npx card",
    "business card"
  ],
  "author": "suraj Ojha",
  "license": "MIT",
  "files": [
    "bin/card.js",
    "bin/output"
  ],
  "devDependencies": {
    "boxen": "^2.1.0",
    "chalk": "^2.4.1",
    "standard": "^12.0.1"
  },
  "bugs": {
    "url": "https://github.com/bnb/bitandbang/issues"
  },
  "dependencies": {},
  "publishConfig": {
    "registry": "https://npm.registry.github.com/"
  }
}

你是不是指的是404错误,而不是403错误? - evolutionxbox
为什么要重新发布别人的软件包?话虽如此,你是否记得要实际编辑 package.json 以便 npm 知道将其发布为你的项目? - Mike 'Pomax' Kamermans
我尝试过更改不同的包名,但没有成功。 - Suraj Oberai
我并不想重新发布别人的软件包或窃取别人的工作成果。这个注册表或软件包可以帮助你构建所谓的npx卡片,每个人都在使用这个软件包来制作自己的卡片,我也是如此。@Mike'Pomax'Kamermans - Suraj Oberai
如果这是您自己的项目,并且遵循了常规的npm init过程和常规的npm login,那么至少除了在Stackoverflow上询问之外,还要询问NPM工作人员出了什么问题,因为您正在使用他们的工具并且他们是应该解决问题的主要权威。 Stackoverflow是您尝试了所有明显的寻找/询问地方并且什么都没有找到之后提问的地方。 - Mike 'Pomax' Kamermans
https://dev59.com/UFkT5IYBdhLWcg3wELgl - quine9997
4个回答

1
更新:我认为这是由于您家目录中的 .npmrc 引起的问题。更改 $HOME 变量似乎也会导致它失败。删除该文件,并重新登录 npm,似乎可以解决该问题。
除了答案之外,Suraj Oberai 你的问题非常清晰明了,包含了所有必要的信息,我认为你不应该被贬低。
我已经发布了许多 npm 包,但这是我自己第一次遇到这个问题。这很奇怪,因为这个和之前我发布的包几乎没有什么区别。我不得不通过拿一个工作正常的包(多次无用的发布后)慢慢地将其转换成我尝试引发错误的包来跟踪问题,只有到达两个项目之间实际上没有任何不同的程度才停止。唯一的区别就是 shell 的 HOME 环境变量。
这绝对是 npm 的一个 bug。看起来上面的错误是默认错误,所以我的更改可能不能为您解决此问题。

谢谢 @jeff,这对我来说意义重大,我会尝试您提出的更改。 - Suraj Oberai
答案刚刚进行了重大更新(FYI Suraj Oberai - Jeff Hykin

0

它在另一个注册表中起作用了(也许他们更新了它?):

 "publishConfig": {
    "registry": "https://registry.npmjs.org/"
  }


0

GitHub NPM注册表用于私有包。 包名必须被限定范围。 "name": "suraj-ojha" 在GitHub上不起作用。 它需要像这样的东西 @suraj/ojha@bnb/bitandbang(因为这是您的GitHub用户名和存储库名称)。

如果您不打算发布私有包并希望将其发布到公共包,请删除package.json中的publishConfig部分,以便npm publish使用默认的公共注册表。


0

publishConfig URL 可能是错误的。 您可以尝试在 package.json 中添加 publishConfig 选项:

"publishConfig": {
    "registry":"https://npm.pkg.github.com"
},

我不确定所有者是否真的必要。你可以尝试没有它的所有者。 :( - Muzaffer Yıldırım
我做了所有这些事情,到底“username@version不在npm注册表中”是什么意思? - Suraj Oberai
我修改了你建议的URL后,分享了package.json文件。npm/cli似乎出现了问题。我在GitHub上检查了一下,问题仍未完全解决。 - Suraj Oberai
相信我,在我的情况下,该URL问题仍然存在。我为什么要撒谎呢? - Suraj Oberai

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接