5

My current workflow:

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test
        run: |
          npm install yarn -g
          yarn
          yarn test
        env:
          CI: true
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

I have setup my NPM_TOKEN in the repo secrets area.

The token is also in use on Netlify, and the netlify build process works.

When this workflow runs, I get a 404 for any of my private packages.

What am I doing wrong?

tk421
  • 5,775
  • 6
  • 23
  • 34
Guy Bowden
  • 4,997
  • 5
  • 38
  • 58

3 Answers3

6

Found a fix:

Write out .npmrc as part of the job instead of relying on an env variable.

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
          npm install yarn -g
          yarn
          yarn test
        env:
          CI: true
Guy Bowden
  • 4,997
  • 5
  • 38
  • 58
0

I think the following question/answer might be related.

Yarn can't find private Github npm registry

If this is the same issue, package proxying from the npm registry doesn't work with yarn yet.

peterevans
  • 34,297
  • 7
  • 84
  • 83
0

In case you have an existing .npmrc and ONLY want to append the token into the existing file instead of overwriting it, this worked for me.

*** NOTE: The echo includes a -e argument and a \n in order to prepend a newline. Also instead of > which overwrites the .npmrc file there is a >> which appends to the .npmrc file.

      - name: npm install, build, and test
        run: |
          echo -e "\n//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
          npm install yarn
          yarn
          yarn test
        env:
          CI: true
Mr. Young
  • 2,364
  • 3
  • 25
  • 41