I’m encountering an ERR_PNPM_FETCH_401 error when trying to install a private npm package from GitHub Packages using GitHub Actions in a monorepo setup. The error message indicates an unauthorized request, despite setting up authentication as described in the documentation. Here’s the error message:
ERR_PNPM_FETCH_401 GET https://npm.pkg.github.com/download/@francislagares/jobber-shared/1.0.5/17a9104c0c7f6c748907155929f68e617e94a62e: Unauthorized - 401
An authorization header was used: ***
These authorization settings were found:
//npm.pkg.github.com/:_authToken=NPM_[hidden]
Here is my current github workflow file:
name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [22.x]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path | tr -d 'n')" >> $GITHUB_ENV
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://npm.pkg.github.com'
scope: '@francislagares'
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install Dependencies
run: pnpm install
env:
NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Prisma ORM schema to the database
run: pnpm prisma migrate deploy
- name: Run Tests
run: pnpm test:ci
Here is my .npmrc file:
@francislagares:registry=https://npm.pkg.github.com/francislagares
//npm.pkg.github.com/:_authToken=NPM_TOKEN
Steps Taken:
- Secret Setup: I’ve added the GITHUB_TOKEN as a secret in the repository settings with ALL privileges.
- Registry Configuration: Configured the .npmrc file to authenticate with GitHub Packages.
- I’ve tried SO many different configurations and tweaks but still get the same error.
Any insights or suggestions would be greatly appreciated!