无法从 GitHub Actions 发布到 npm:`<package> is not in the npm registry` 错误
Posted
技术标签:
【中文标题】无法从 GitHub Actions 发布到 npm:`<package> is not in the npm registry` 错误【英文标题】:Cannot publish to npm from GitHub Actions: `<package> is not in the npm registry` error 【发布时间】:2021-12-24 14:05:36 【问题描述】:我可以从命令行成功发布我的 npm 包,但是当我尝试使用自动化令牌通过 GitHub 操作自动发布它时,我得到:
npm notice name: stereo-img
npm notice version: 0.4.0
npm notice package size: 12.3 kB
npm notice unpacked size: 39.7 kB
npm notice shasum: 9b9cf99342b7bf2e6ff36f9fe6448a5d31ed39fb
npm notice integrity: sha512-3vwZWK4Ndddvr[...]zr02dd0Mb9KgA==
npm notice total files: 10
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/stereo-img - Not found
npm ERR! 404
npm ERR! 404 'stereo-img@0.4.0' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-11-12T07_21_22_598Z-debug.log
Error: Process completed with exit code 1.
我的 GitHub Actions 工作流程如下:
name: Publish package on npm
on:
release:
types: [created]
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: $secrets.npm_token
【问题讨论】:
【参考方案1】:我能够通过确保在actions/setup-node@v2
步骤中使用registry-url
来修复它:
name: Publish package on npm
on:
release:
types: [created]
jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: $secrets.npm_token
【讨论】:
以上是关于无法从 GitHub Actions 发布到 npm:`<package> is not in the npm registry` 错误的主要内容,如果未能解决你的问题,请参考以下文章
利用GitHub-Actions将Hugo博客自动发布到GitHub和Gitee Pages
CI/CD现代史,从Jenkins到GitHub Actions
GitHub Actions 无法设置 Python 虚拟环境