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?

More than 1 year has passed since last update.

npm publish を子プロセス上で実行すると認証が通らない場合の対応

Posted at

問題

npm publish をする際、認証を通すために npm adduser すると思います。

普通にシェル上でそれぞれのコマンドを叩くなら特に問題ありませんが、例えば package.json の scripts で npm publish コマンドを使っていたり、何らかのシェルスクリプトで実行する場合、親プロセス上で npm adduser をしていても認証が通りません。
npm adduser も同じプロセス上で実行すれば良いんですが、そうすると今度は毎回実行の度にログインあるいはワンタイムパスワードの入力を1回か2回実行する必要があり非常に面倒です。

対応

.npmrc という npm の挙動を制御する仕組みがあり、ここにアクセストークンを記載することができます。
そのレポジトリに .npmrc を用意し、アクセストークンを記載しておくと子プロセス上でも認証が通るようになります。

.npmrc
//registry.npmjs.org/:_authToken=YOUR_ACCESS_TOKEN

これだけです。

アクセストークンは npmjs.com のアカウントメニューの Access Tokens のページで作成できます。

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?