0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[npm, pnpm] Trusted Publishingで躓いた点

Posted at

前提条件

  • npm側でTrusted Publishing設定を済ませている
  • pnpm publishでnpmにアップロードしたいモチベーション

躓き集

ERR_PNPM_GIT_UNKNOWN_BRANCH

問題

Run pnpm publish --access public
 ERR_PNPM_GIT_UNKNOWN_BRANCH  The Git HEAD may not attached to any branch, but your "publish-branch" is set to "master|main".

解決
--no-git-checksオプションを忘れずに

   - name: Publish to npm
-      run: pnpm publish --access public
+      run: pnpm publish --access public --no-git-checks

ENEEDAUTH

問題

npm error code ENEEDAUTH
npm error need auth This command requires you to be logged in to https://registry.npmjs.org/
npm error need auth You need to authorize this machine using `npm adduser`
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2026-01-24T03_19_30_445Z-debug-0.log

解決
pnpm/action-setup@v4アクションだけではなく、actions/setup-node@4アクションでregistry-urlを指定する必要がありました

    - name: Checkout repository
      uses: actions/checkout@v4

+    - name: Setup Node.js
+      uses: actions/setup-node@v4
+      with:
+        node-version: 24
+        registry-url: "https://registry.npmjs.org"

    - name: Setup pnpm
      uses: pnpm/action-setup@v4
      with:

E404

問題

npm notice
npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access
npm notice Access token expired or revoked. Please try logging in again.
npm error code E404
npm error 404 Not Found - PUT https://registry.npmjs.org/@konbraphat51%2faffectiveslidervue - Not found
npm error 404
npm error 404  '@konbraphat51/affectiveslidervue@0.0.2' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2026-01-24T03_37_29_705Z-debug-0.log

解決
なんと、node.jsのバージョンが24以上じゃないとtrusted publishingが使えないようです。

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
-       node-version: 22.x
+       node-version: '24'
        registry-url: "https://registry.npmjs.org"

最終的なyamlファイル

.github/workflows/publish.yml
name: Publish

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '24'
        registry-url: "https://registry.npmjs.org"

    - name: Setup pnpm
      uses: pnpm/action-setup@v4
      with:
        version: 10
    
    - name: Install dependencies
      run: pnpm i --frozen-lockfile

    - name: Run tests
      run: pnpm run test:run
        
    - name: Build package
      run: pnpm run build
    
    - name: Publish to npm
      run: pnpm publish --access public --no-git-checks
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?