LoginSignup
5
6

More than 5 years have passed since last update.

package.json の dependencies の git:// が動かない

Posted at

問題

@bouzuya の Hubot スクリプトは git:// でインストールすることを推奨している (例: https://github.com/bouzuya/hubot-twada ) 。しかし、最近それらがうまく機能せず、package.jsondependenciesgit:// な url を指定しても npm install で失敗することがある。

以前はそんなことなかったのだけれど、ここ数日ひどい。ちなみに発生するエラーは以下のようなもの。

npm ERR! git fetch -a origin (git://github.com/bouzuya/hubot-randict.git) fatal: unable to connect to github.com:
npm ERR! git fetch -a origin (git://github.com/bouzuya/hubot-randict.git) github.com: Name or service not known
npm ERR! git fetch -a origin (git://github.com/bouzuya/hubot-hatena-bookmark-hotentry.git) fatal: unable to connect to github.com:
npm ERR! git fetch -a origin (git://github.com/bouzuya/hubot-hatena-bookmark-hotentry.git) github.com: Name or service not known

なぜか名前解決に失敗したようなエラーが出る (ネットワークに問題があるわけではない) 。

解決策

git:// を使わず、.tar.gz を使う。

GitHub は tag (releases) や master に対して archive url (.tar.gz) が提供されるので、それを使う。

before

"hubot-bbn-tags": "git://github.com/bouzuya/hubot-bbn-tags.git#1.0.0"

after

"hubot-bbn-tags": "https://github.com/bouzuya/hubot-bbn-tags/archive/1.0.0.tar.gz"

単純置換なので簡単に移行できるし、エラーも現状起きていないようだ。npm install の時間も短縮できるのでなかなか良い。

その他

もっと良い対策 (根本的なもの) あると思うのだけど、とりあえず動き、気になる問題もないのでシェア。

5
6
1

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
5
6