LoginSignup
10
10

More than 5 years have passed since last update.

Proxy下のWindows版Atomでscriptパッケージがインストールできない問題

Last updated at Posted at 2016-04-11

はじめに

私の端末はHTTP及びHTTPS以外は通さないプロクシを通さなければ外部に出ることが出来ない。
基本的にはHTTPとHTTPSで事足りるのだが、今回このプロクシのせいでscriptパッケージがインストールできなくなってしまった。
恐らく私と同じような問題に悩む方はそう多くはないと思うが、日本語で情報を残す。

2016/04/13 Update

正しい解決方法が判明したので編集した。

前提条件

  • Windows 7 32bit版
  • Atom 1.6.2
  • HTTP及びHTTPS以外を通さないプロクシが立ちはだかっている
  • gitインストール済み
  • 環境変数HOMEUSERPROFILEと別の場所に設定 ← 非常に重要

発生した問題

$ apm install script
Installing script to C:\Users\fkfk\.atom\packages failed

npm WARN addRemoteGit Error: Command failed:
npm WARN addRemoteGit     at ChildProcess.exithandler (child_process.js:658:15)
npm WARN addRemoteGit     at ChildProcess.emit (events.js:98:17)
npm WARN addRemoteGit     at maybeClose (child_process.js:766:16)
npm WARN addRemoteGit     at Process.ChildProcess._handle.onexit (child_process.js:833:5)
npm WARN addRemoteGit  git://github.com/monsterkodi/node-simple-plist.git resetting remote C:\Users\fkfk\.atom\.apm\_git-remotes\git-github-com-monsterkodi-node-simple-plist-git-6a71a541 because of error: { [Error: Command failed: ] killed: false, code: 1, signal: null }
npm ERR! git clone --template=C:\Users\fkfk\.atom\.apm\_git-remotes\_templates --mirror git://github.com/monsterkodi/node-simple-plist.git C:\Users\fkfk\.atom\.apm\_git-remotes\git-github-com-monsterkodi-node-simple-plist-git-6a71a541: Cloning into bare repository 'C:\Users\fkfk\.atom\.apm\_git-remotes\git-github-com-monsterkodi-node-simple-plist-git-6a71a541'...
npm ERR! git clone --template=C:\Users\fkfk\.atom\.apm\_git-remotes\_templates --mirror git://github.com/monsterkodi/node-simple-plist.git C:\Users\fkfk\.atom\.apm\_git-remotes\git-github-com-monsterkodi-node-simple-plist-git-6a71a541: fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\\opt\\Atom\\resources\\app\\apm\\bin\\node.exe" "D:\\opt\\Atom\\resources\\app\\apm\\node_modules\\npm\\bin\\npm-cli.js" "--globalconfig" "C:\\Users\\fkfk\\.atom\\.apm\\.apmrc" "--userconfig" "C:\\Users\\fkfk\\.atom\\.apmrc" "install" "D:\\opt\\msys32\\tmp\\d-116311-2396-15dz5pn\\package.tgz" "--target=0.34.5" "--arch=ia32"
npm ERR! node v0.10.40
npm ERR! npm  v2.13.3
npm ERR! code 128

npm ERR! Command failed: Cloning into bare repository 'C:\Users\fkfk\.atom\.apm\_git-remotes\git-github-com-monsterkodi-node-simple-plist-git-6a71a541'...
npm ERR! fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

要はgit://でアクセスしようとして失敗している。

git configでどうにかしようと試みる

git://でアクセスしようとするのが悪いのだから、これをhttp://なりhttps://なりに読み替えれば問題なくなるはずである。

$ git config --global url."https://".insteadOf git://

これで問題ないはずと思い、おもむろにapm install scriptを実行すると先ほどと同じエラーが発生してしまった。
念のためgit://なリポジトリをgit cloneしてみたが正常に取得出来たので、gitそのものは正しく動いているようだ。

Linuxで試してみる

調べてみても前段のgit configをすれば解決しているIssueしか見つけられずしばらく頭を抱えていたのだが、ふとLinuxで試すとどうなるかと思いやってみた。
LinuxにはAtomをインストールしていないのでnpmでやってみることにする。

$ git clone https://github.com/rgbkrk/atom-script.git
$ cd atom-script
$ npm install --save
(snip)
$

なんと正常に通ってしまった。
念のため同一操作をWindows上のnyagoscmd.exebash(MsysGIT)、zsh(msys2)で試してみたがどれも通らなかったので、どうやらnpmのWindows固有のバグのようである。

.gitconfigの場所を確認する(2016/04/13追記)

git config --globalとした場合、LinuxやMacの場合は$HOME/.gitconfigに記録される。
Windowsだと、nyagoscmd.exebash等で実行した場合に環境変数HOMEが定義されていればそちらを見に行くが、なければUSERPROFILEの値をHOMEとして利用する。
しかし、npmから実行される場合、環境変数HOMEを考慮せずに%USERPROFILE%\.gitconfigを見に行ってしまう。
そのため、git config --globalで読み替えの設定を行っていたとしても、npm内部でgit cloneを行うときにはそもそも.gitconfigを読まないのでこのような問題が発生するようだ。
解決方法としては

  1. 環境変数HOMEを消す
  2. 環境変数HOMEUSERPROFILEを同一の値にする
  3. %USERPROFILE%\.gitconfig%HOME%\.gitconfigのシンボリックリンクまたはハードリンクを作成する

のどれかとなるが、私は1と2の対応は論外なので3で対応したいところである。
が、Windowsでシンボリックリンクを作成するには管理者権限または特権SeCreateSymbolicLinkPrivilegeが必要となるが、残念ながら私のユーザーにはどちらも設定されていない。
また、ハードリンクを作成しようにも環境変数HOMEUSERPROFILEと別ドライブにしているためこれも不可となる。
どうしようもないので、取り急ぎ%HOME%\.gitconfig%USERPROFILE%\.gitconfigにコピーすることにした。
.gitconfigが更新されたら都度コピーするように何かしら行わなければならないが、今更HOMEの値を変更するよりはマシだろう。

さらに追記

npmでのみ試してapmを試していなかったので先ほどやってみたのだが、apmでやると見事にエラーが出てしまうことが分かった。
恐らく内部のnpmのバージョンが古いのが問題なのだろうと思うが、結局下記の方法でやるほかないようだ。

$ cp $HOME/.gitconfig $USERPROFILE/.gitconfig
$ cd /path/to/dir
$ git clone https://github.com/rgbkrk/atom-script.git
$ cd atom-script
$ git checkout -b v3.6.3 refs/tags/v3.6.3 # リリース版を使いたい場合
$ npm install
$ apm link

これでもLinuxでgit clone及びnpm installをしなくてもよくなった分いくらかマシである。

やっつけ対応

apm linkでひとまず利用できるようにする

バグの原因を探るほうが建設的だが、scriptが利用できないのは致命的なので取り急ぎLinux上でnpm installが通ったディレクトリをまるまるWindowsに持ってきてみた。

$ cd /path/to/atom-script
$ apm link

node-gypでコンパイルしたものが混じっていればアウトだが、運よくそのようなものは混じっていなかったようで今のところ正常に利用できている。

付録: 別ブランチを切ってpackages.jsonを修正する

今回私がやった方法はWindows以外の端末がある(またはVM等でLinuxを利用できる)ことが前提だが、atom-script及び問題となるパッケージに依存しているものを根こそぎローカルにcloneし、packages.jsonを修正する手もある。
修正が必要となるパッケージは以下の通り。

noonパッケージが依存しているsimple-plistの指定がgit://となっているため、これをhttps://に修正し、それ以外のpackages.jsonfile://で指定すれば動くはずである。
アップデートのたびにそれぞれのリポジトリの更新を追ってマージするのが非常に面倒と感じたため、私はこの方法は試してもいない。

10
10
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
10
10