question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GitHub Action failing to find NPM_TOKEN

See original GitHub issue

I’m trying to switch from publishing directly to npm (which worked fine) to using GitHub Packages with an organisation scoped package name.

I’ve changed my package name in package.json, added the necessary publishConfig e.g.

"publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },

And changed my Action steps to use NODE_AUTH_TOKEN instead of NPM_TOKEN as per the docs, but when I merge a branch and trigger the action I get the following warning and the package is never published (though version tags and changelog are updated, so annoyingly it doesn’t flag as a failed run):

 ✔  success   Wrote authentication token string to /home/runner/.npmrc
⚠  warning   Error: Failed to replace env in config: ${NPM_TOKEN}

NPM_TOKEN is set in my repository Secrets on GitHub.

Here’s the Action setup:

name: Publish

on:
  push:
    branches: [main]

jobs:
  release:
    runs-on: ubuntu-latest

    # this check needs to be in place to prevent a publish loop with auto and github actions
    if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"

    steps:
      - uses: actions/checkout@v2
        with:
          # Needed for branch protection override
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Prepare repository
        run: git fetch --unshallow --tags

      - name: Use Node.js 12.x
        uses: actions/setup-node@v1
        with:
          node-version: 12.x

      - name: Cache node modules
        uses: actions/cache@v2
        with:
          path: node_modules
          key: node-modules-${{ hashFiles('package-lock.json') }}
          restore-keys: |
            node-modules-${{ hashFiles('package-lock.json') }}

      - name: Create release
        env
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          npm ci
          npm run build
          npm run release

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
theAdhocracycommented, Feb 24, 2021

Reviewed, couple of small suggestions but all looks good ☺Thanks again for all your help

1reaction
hipstersmoothiecommented, Feb 23, 2021

I’ve made a PR to improve those docs. Would you mind reviewing #1828?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Github Actions step fails to detect packages from private NPM ...
Hello. I'm giving SWA some advanced scenario where I've published a private package on Github Packages Registry in a repo I own, then...
Read more >
Releasing from GitHub Actions npm ERR!! code ENEEDAUTH
I have a GitHub action invoke npx multi-semantic-release , passing the github token and npm token env vars. This is all visible here....
Read more >
Github Actions: Missing npm's token · Issue #14 · nice-registry ...
The release action is failing due to npm not being able to authenticate the github CI ... fix: create .npmrc using npm token...
Read more >
[BUG] Running npm ci in GitHub Actions erroneously uses ...
Push the project to GitHub. Watch the action fail with the following error in the GitHub Actions details page: npm ERR! code E401...
Read more >
Invalid format for "pnpm store path" when NPM token is missing
And a GitHub action that installs and caches dependencies using the ... Error: Unable to process file command 'output' successfully.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found