'NPM attempts to publish twice

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?



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 magynhard