NPM 尝试发布两次

Ala*_*ect 5 npm npm-publish

我正在维护我的第一个npm包,所以这可能是我的一个错误。构建我的包并将其提交到git后,下一步是:

\n
$ npm version patch\n$ npm publish\n
Run Code Online (Sandbox Code Playgroud)\n

输出(节略)如下:

\n
\nnpm notice \nnpm notice   @mememe/p3-model@0.7.2\nnpm notice === Tarball Contents === \nnpm notice 188B  README.md                \nnpm notice 4.5kB dist/doc.d.ts\n\n  (etc) \n            \nnpm notice 792B  package.json             \nnpm notice === Tarball Details === \nnpm notice name:          @mememe/p3-model                       \nnpm notice version:       0.7.2                                   \nnpm notice filename:      @mememe/p3-model-0.7.2.tgz             \nnpm notice package size:  6.2 kB                                  \nnpm notice unpacked size: 23.2 kB                                 \nnpm notice shasum:        cb5588ee626efc21532845c608fdb05a5fcd4db3\nnpm notice integrity:     sha512-s7IK2HSXCNTUk[...]ZHxDgAOIr4Cnw==\nnpm notice total files:   11                                      \nnpm notice \nnpm notice Publishing to https://registry.npmjs.org/\n\xe2\xb8\xa8\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xb8\xa9 \xe2\xa0\x87 : notice Publishing to https://registry.npmjs.org/\n
Run Code Online (Sandbox Code Playgroud)\n

到目前为止,一切都很好。但后来不知何故,它尝试再次发布并收到我在旧版本之上发布的错误。输出继续:

\n
> @mememe/p3-model@0.7.2 publish\n> npm publish\n\nnpm notice \xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xb8\xa9 \xe2\xa0\x87 : notice Publishing to https://registry.npmjs.org/\nnpm notice   @mememe/p3-model@0.7.2\nnpm notice === Tarball Contents === \nnpm notice 188B  README.md                \nnpm notice 4.5kB dist/doc.d.ts            \nnpm notice 6.5kB dist/doc.js     \n\n  (etc)\n             \nnpm notice === Tarball Details === \nnpm notice name:          @mememe/p3-model                       \nnpm notice version:       0.7.2                                   \nnpm notice filename:      @mememe/p3-model-0.7.2.tgz             \nnpm notice package size:  6.2 kB                                  \nnpm notice unpacked size: 23.2 kB                                 \nnpm notice shasum:        cb5588ee626efc21532845c608fdb05a5fcd4db3\nnpm notice integrity:     sha512-s7IK2HSXCNTUk[...]ZHxDgAOIr4Cnw==\nnpm notice total files:   11                                      \nnpm notice \nnpm ERR! code E403\nnpm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@mememe%2fp3-model - You cannot publish over the previously published versions: 0.7.2.\nnpm ERR! 403 In most cases, you or one of your dependencies are requesting\nnpm ERR! 403 a package version that is forbidden by your security policy, or\nnpm ERR! 403 on a server you do not have access to.\n\xe2\xb8\xa8\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xa0\x82\xe2\xb8\xa9 \xe2\xa0\x87 : notice Publishing to https://registry.npmjs.org/\nnpm ERR! A complete log of this run can be found in:\n\n
Run Code Online (Sandbox Code Playgroud)\n

我只输入了npm publish一次命令。该命令的某些操作(可能是 中的选项package.json)是否会导致此问题?

\n

正确的包已发布,我可以在其他项目中使用它。但这个错误有点令人不安。有什么建议么?

\n

小智 10

我有同样的问题,刚刚解决了。

我的问题是,我在 my 中定义了一个scriptwith ,所以它在之后/之前再次被触发。publishpackage.json

其背后的想法是对我用于构建、测试、生成文档和发布的命令有一个提示(如命令列表)。但不幸的是,该命令一直被触发两次。

就我而言,package.json 如下所示:

{
  "name": "my-package",
  "version": "1.0.0",
  "scripts": {
    "build": "echo here could be a build job",
    "test": "jasmine",
    "publish": "npm publish"
}
Run Code Online (Sandbox Code Playgroud)

检查您的package.json条目是否scripts有名为 的键publish。如果您有一个带有 key 的条目publish,请完全删除此行或为您的脚本使用不同的键。