NPM publish does not work with the correct NPM_TOKEN

I am struggling to release the new version of multiple packages from one repository.
I am using semantic-release, with a custom plugin to publish multiple packages from Angular monorepo.

The script creates .npmrc file in each of the about to be published folders/packages, it even creates ~/.npmrc, just to be sure.

.npmrc file contains: //

One of the recent failed attempts:

The error:
npm ERR! need auth auth required for publishing
npm ERR! need auth You need to authorize this machine using npm adduser

Not sure why this is happening and not super familiar with deploying to the NPM registry but could you try adding npm whoami to your .travis.yml file to see if you are authenticated properly outside your code?

Hi @dominic, thanks for super fast reply.

I added it just before my build starts and I am getting the exact same error: says:

npm ERR! need auth You need to authorize this machine using `npm adduser`

From what the log tells us, the token is properly decrypted and written to dist/core/.npmrc.

I suggest reviewing your tool’s/tools’ documentation to ensure it is set up correctly.

@BanzaiMan, in the reply to @dominic I pasted a link to another build, where I executed npm whoami in the .travis.yml file itself.

So…NPM_TOKEN is the correct one, yet npm still does not recognize the user.
Therefore no tool other than npm and travis itself involved.

funny enough. I replaced my npm publish command with yarn and now it works perfectly fine.

Glad to hear you made progress but the mystery remains!

Going back to when you added npm whoami to your .travis.yml file, do you confirm that the .npmrc file was created before it was called?

If it helps, here’s a simple config showing how to setup your NPM authentication in a build:

And here’s the resulting build:

Remember also that npm whoami needs to be called in the same directory where your .npmrc file resides.

Hope this helps!