【问题标题】:Unable to publish an npm package with github actions无法使用 github 操作发布 npm 包
【发布时间】:2022-10-21 22:06:31
【问题描述】:

我正在尝试通过 github 操作在 github register 和 npm register 上发布我的 npm 包。 github 一个成功,但另一个失败,如下所示:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com/nullndr
npm ERR! need auth You need to authorize this machine using `npm adduser`

为什么我需要npm adduser。我使用自动化令牌,还不够吗?

这是我的工作流程文件:

# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - run: npm ci

  publish-gpr:
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://npm.pkg.github.com/
          scope: "@nullndr"
      - run: npm install
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_GITHUB_TOKEN }}

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          registry-url: https://registry.npmjs.org/
      - run: npm install
      - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_NPM_TOKEN }}

我错过了什么?

【问题讨论】:

    标签: npm github-actions


    【解决方案1】:

    检查 PUBLISH_NPM_TOKEN 是否出现在您的存储库环境变量中。

    将 PUBLISH_NPM_TOKEN 添加到环境变量将不起作用。您需要将其添加为存储库环境。

    Repository Environments

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2022-09-24
      • 2023-02-14
      • 1970-01-01
      • 2021-02-05
      • 2020-01-19
      • 1970-01-01
      • 2018-11-25
      • 2023-02-14
      相关资源
      最近更新 更多