NPM attempts to publish twice
Asked Answered
I

1

7

I am maintaining my first npm package so this might be an error on my part. Once build my package and commit it to git the next step is:

$ npm version patch
$ npm publish

The output (abridged) is as follows:


npm notice 
npm notice 📦  @mememe/[email protected]
npm notice === Tarball Contents === 
npm notice 188B  README.md                
npm notice 4.5kB dist/doc.d.ts

  (etc) 
            
npm notice 792B  package.json             
npm notice === Tarball Details === 
npm notice name:          @mememe/p3-model                       
npm notice version:       0.7.2                                   
npm notice filename:      @mememe/p3-model-0.7.2.tgz             
npm notice package size:  6.2 kB                                  
npm notice unpacked size: 23.2 kB                                 
npm notice shasum:        cb5588ee626efc21532845c608fdb05a5fcd4db3
npm notice integrity:     sha512-s7IK2HSXCNTUk[...]ZHxDgAOIr4Cnw==
npm notice total files:   11                                      
npm notice 
npm notice Publishing to https://registry.npmjs.org/
⸨⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⸩ ⠇ : notice Publishing to https://registry.npmjs.org/

So far so good. But then somehow it attempts to publish again and gets an error that I am publishing on top of an old version. The output continues:

> @mememe/[email protected] publish
> npm publish

npm notice ⠂⠂⠂⠂⠂⠂⠂⠂⸩ ⠇ : notice Publishing to https://registry.npmjs.org/
npm notice 📦  @mememe/[email protected]
npm notice === Tarball Contents === 
npm notice 188B  README.md                
npm notice 4.5kB dist/doc.d.ts            
npm notice 6.5kB dist/doc.js     

  (etc)
             
npm notice === Tarball Details === 
npm notice name:          @mememe/p3-model                       
npm notice version:       0.7.2                                   
npm notice filename:      @mememe/p3-model-0.7.2.tgz             
npm notice package size:  6.2 kB                                  
npm notice unpacked size: 23.2 kB                                 
npm notice shasum:        cb5588ee626efc21532845c608fdb05a5fcd4db3
npm notice integrity:     sha512-s7IK2HSXCNTUk[...]ZHxDgAOIr4Cnw==
npm notice total files:   11                                      
npm notice 
npm ERR! code E403
npm ERR! 403 403 Forbidden - PUT https://registry.npmjs.org/@mememe%2fp3-model - You cannot publish over the previously published versions: 0.7.2.
npm ERR! 403 In most cases, you or one of your dependencies are requesting
npm ERR! 403 a package version that is forbidden by your security policy, or
npm ERR! 403 on a server you do not have access to.
⸨⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⠂⸩ ⠇ : notice Publishing to https://registry.npmjs.org/
npm ERR! A complete log of this run can be found in:

I only entered the npm publish command once. Is there some action of this command (perhaps an option in package.json) that would cause this?

The correct package gets published and I can use it in other projects. But this error is a bit disconcerting. Any suggestions?

Iphigenia answered 3/4, 2022 at 22:27 Comment(0)
C
14

I had the same issue and just solved it.

My problem was, that i had defined a script with publish in my package.json, so it was fired after/before again.

The idea behind that was to have a hint (like a command list) about the commands i use for building, testing, generating documentation and publishing. But unfortunately then the command was fired twice all the time.

In my case, the package.json looked like this:

{
  "name": "my-package",
  "version": "1.0.0",
  "scripts": {
    "build": "echo here could be a build job",
    "test": "jasmine",
    "publish": "npm publish"
}

Check your package.json for a entry at scripts which key is named publish. If you have an entry with the key publish, then remove this line entirely or use a different key for your script.

Cruciform answered 9/5, 2022 at 17:56 Comment(2)
My problem did get mitigated but I didn't know the reason. I did edits to package.json for different reasons and ended up taking out the script as you suggested.Iphigenia
I had the same problem this week. Learning to make packages, and had defined "publish": "npm publish --access=public". Removed it, went to this post to answer it, and saw the it was already answered! :)Martinet

© 2022 - 2024 — McMap. All rights reserved.