Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ENEEDAUTH issue when running "npm publish" within a monorepo on a ci environment #6184

Closed
2 tasks done
vighnesh153 opened this issue Feb 18, 2023 · 2 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release

Comments

@vighnesh153
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

I have a monorepo and I am trying to publish all the packages ./packages/* to NPM using Github Actions. When I run the npm publish command, I get the following error:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`

I have already provided the NODE_AUTH_TOKEN environment variable but it is still not able to authenticate that.

There is an open issue which looks similar to this but it has got no comments (#5805)

Expected Behavior

The packages should be published without ENEEDAUTH error.

Steps To Reproduce

  1. I have the following configuration for Github Actions publish workflow
name: Publish all packages to NPM

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "lts/*"

      - name: Install latest NPM
        run: npm install -g npm@latest

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build:packages

      - name: Config git metadata
        run: |
          git config --global user.name 'Vighnesh Raut'
          git config --global user.email 'me@vighnesh153.com'

      - name: Publish the packages
        run: |
          npm publish --workspace=packages
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
          NPM_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  1. Code setup
  • Create a packages directory and add it in the root package.json
"workspaces": [
    "packages/*"
  ]
  • Create 1 or 2 packages and add the required stuff in the package.json file
{
  "name": "...",
  "version": "0.1.0",
  "description": "...",
  "private": false,
  "publishConfig": {
    "access": "public"
  },
  "repository": {
    "type": "git",
    "url": "..."
  }
}
  1. Push the files to github and trigger the worflow

Environment

  • npm: 9.5.0
  • Node.js: v18.14.0
  • OS Name: Ubuntu 22.04.1 LTS
  • System Model Name: Github Actions CI Runner v2.301.1
  • npm config:
; node bin location = /opt/hostedtoolcache/node/18.14.0/x64/bin/node
; node version = v18.14.0
; npm local prefix = /home/runner/work/vighnesh1[53](https://github.com/vighnesh153/vighnesh153-turbo/actions/runs/4209840637/jobs/7307091317#step:10:54)-turbo/vighnesh153-turbo
; npm version = 9.5.0
; cwd = /home/runner/work/vighnesh153-turbo/vighnesh153-turbo
; HOME = /home/runner
; Run `npm config ls -l` to show all defaults.
@vighnesh153 vighnesh153 added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Feb 18, 2023
@caugner
Copy link

caugner commented May 11, 2023

@vighnesh153 I ran into this today, and it turns out that npm doesn't usually accept an auth token via an environemnt variable like NODE_AUTH_TOKEN or NPM_TOKEN, unless you specify this explicitly in an .npmrc file, which the setup-node action can create for you:

Please note that you need to set the registry-url to https://registry.npmjs.org/ in setup-node to properly configure your credentials. (Source)

In your example:

       - name: Setup Node.js
         uses: actions/setup-node@v3
         with:
           node-version: "lts/*"
+          registry-url: "https://registry.npmjs.org"

Hope this helps! 🤞

@vighnesh153
Copy link
Author

This was the issue. Thanks a lot. I wish the error message was more descriptive.

mikechu-optimizely pushed a commit to optimizely/react-sdk that referenced this issue Sep 25, 2023
mikechu-optimizely added a commit to optimizely/react-sdk that referenced this issue Sep 25, 2023
* Correction to release workflow

based on npm/cli#6184

* Fix for EOL character

* Add gitattributes file for eol=lf

* Add extra line at EOF

---------

Co-authored-by: Mike Chu <mike.chu@optimizely.com>
shirish87 added a commit to shirish87/browserstack-client that referenced this issue Jan 31, 2024
HammadB added a commit to chroma-core/chroma that referenced this issue May 7, 2024
HammadB added a commit to chroma-core/chroma that referenced this issue May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release
Projects
None yet
Development

No branches or pull requests

2 participants