NodeJS GitHub操作:NPM发布失败,错误代码为ENEEDAUTH

xdnvmnnf  于 2023-02-08  发布在  Node.js
关注(0)|答案(1)|浏览(452)

我尝试过使用GitHub Actions来实现发布和安装软件包的官方指南:使用粒度权限对包注册中心进行身份验证
失败原因:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://npm.pkg.github.com
npm ERR! need auth You need to authorize this machine using `npm adduser`
    • 包. json**
{
  "name": "@charneykaye/banana",
  "version": "4.0.6",
  "repository": "git@github.com:charneykaye/banana",
  "description": "made by artists in a new algorithmic medium",
  "bin": {
    "banana": "./lib/index.js"
  },
  "author": "Charney Kaye <charney@xj.io>",
  "license": "MIT",
  "scripts": {
    "start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
    "start:windows": "nodemon --watch 'src/**/*.ts' --exec \"npx ts-node\" src/index.ts",
    "create": "npm run build && npm run test",
    "banana": "npx ts-node ./src/index.ts",
    "test": "tsc -p . && jest --coverage --verbose --runInBand"
  },
  "dependencies": {
    "commander": "^10.0.0",
    "figlet": "^1.5.2",
    "octokit": "^1.8.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.12",
    "@babel/preset-env": "^7.20.2",
    "@babel/preset-typescript": "^7.18.6",
    "@jest/globals": "^29.4.1",
    "@types/jest": "^29.4.0",
    "@types/node": "^18.11.18",
    "babel-jest": "^29.4.1",
    "jest": "^29.4.1",
    "nodemon": "^2.0.20",
    "ts-jest": "^29.0.5",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.5"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "testMatch": [
      "**/__tests__/**test.ts",
      "**/__tests__/**test.tsx"
    ]
  }
}
  • . github/工作流/ci. yml*
name: "CI Build & Publish"

on:
  push:
    branches:
      - main

jobs:
  CI:
    runs-on: ubuntu-latest

    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18.14
          cache: 'npm'

      - name: Install npm packages
        run: npm install

      - name: Unit tests
        run: npm test

      - name: Build Banana
        run: npm run banana -- --build --env prod

      - uses: actions/upload-artifact@v3
        with:
          name: banana
          path: ./build/

      - name: Publish NPM package
        run: npm publish
  • .国家防止洗钱委员会*
@charneykaye:registry=https://npm.pkg.github.com
vsikbqxv

vsikbqxv1#

需要再连接两个点,才能获得指向npm publish的令牌
将**.npmrc**替换为

//npm.pkg.github.com/:_authToken=${NPM_CONFIG_TOKEN}
@charneykaye:registry=https://npm.pkg.github.com
always-auth=true

和**.github/workflow/ci.yml**中的最后一个操作

- name: Publish NPM package
        run: npm publish
        env:
          NPM_CONFIG_TOKEN: ${{ secrets.GITHUB_TOKEN }}

相关问题