Chinachu / Mirakurun

A Modern DVR Tuner Server for Japanese TV.
https://chinachu.moe
Apache License 2.0
626 stars 101 forks source link

Windows + Node.js 16 環境でローカルインストールに失敗する [BUG] #116

Closed yuta2k closed 2 years ago

yuta2k commented 2 years ago

Environment (再現している環境)

Issue (不具合の内容)

Windows 環境でローカルインストールしようとすると、サービスの登録を試みてインストールが失敗してしまいます。

> mkdir foo
> cd foo
> npm init
> npm i mirakurun

文字化けしていて恐れ入りますが、この操作で下記が出力されます。

npm ERR! code 1
npm ERR! path C:\git\foo\node_modules\mirakurun
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node bin/postinstall.js
npm ERR! Version: node@v16.13.2 [OK]
npm ERR! 'winser' �́A�����R�}���h�܂��͊O���R�}���h�A
npm ERR! ����\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF������Ă��܂���B
npm ERR! node:child_process:903
npm ERR!     throw err;
npm ERR!     ^
npm ERR!
npm ERR! Error: Command failed: winser -v
npm ERR! 'winser' �́A�����R�}���h�܂��͊O���R�}���h�A
npm ERR! ����\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF������Ă��܂���B
npm ERR!
npm ERR!     at checkExecSyncError (node:child_process:826:11)
npm ERR!     at Object.execSync (node:child_process:900:15)
npm ERR!     at Object.<anonymous> (C:\git\foo\node_modules\mirakurun\bin\postinstall.js:94:41)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1101:14)
npm ERR!     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:981:32)
npm ERR!     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
npm ERR!     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
npm ERR!     at node:internal/main/run_main_module:17:47 {
npm ERR!   status: 1,
npm ERR!   signal: null,
npm ERR!   output: [
npm ERR!     null,
npm ERR!     '',
npm ERR!     "'winser' �́A�����R�}���h�܂��͊O���R�}���h�A\r\n" +
npm ERR!       '����\x94\\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF������Ă��܂���B\r\n'
npm ERR!   ],
npm ERR!   pid: 12420,
npm ERR!   stdout: '',
npm ERR!   stderr: "'winser' �́A�����R�}���h�܂��͊O���R�}���h�A\r\n" +
npm ERR!     '����\x94\\�ȃv���O�����܂��̓o�b�` �t�@�C���Ƃ��ĔF������Ă��܂���B\r\n'
npm ERR! }

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\USER_NAME\AppData\Local\npm-cache\_logs\2022-02-02T10_11_18_486Z-debug-0.log

恐らく原因としては postinstall.js L18

process.env["npm_config_global"]

undefined となり guard が機能せず、後続の winser によるサービス登録の処理が実行されているためです。

軽く調査したところ npm/cli 7 の changelog を見るに、npm config ls -l の中身?を npm_config_* に展開する機能は廃止されています。

この変更が行われる前の以下の環境では同様の操作で Mirakurun のローカルインストールは成功しました。

環境の詳細は割愛しますが、Node.js 周りを Environment セクションと同条件とした Ubuntu 環境にて

$ git clone https://github.com/Chinachu/Mirakurun.git
$ cd Mirakurun
$ # git checkout release/3.8
$ npm i
$ npm run postinstall

をするとやはり npm_config_globalundefined となり、この if 文は通過してしまっていました。 私がここで試したのは非 root ユーザであったため、この先の L39 の guard で止まりましたが、root で実行した場合には同様に意図せずデーモンの登録が試行される恐れがあるかもしれません。

EpgStation さん側の issue と同様の問題のようです。

Expected (期待される動作)

Mirakurun のサポートする Node.js 16 環境(npm も必然的に 8 以降となる)にてグローバルインストールか否かを正確に判定し、Windows にてローカルインストールが正常に行えるようになること。

OSS には不慣れなため、不作法等ありましたら申し訳ありません....

2022/2/2追記: Ubuntu 側のバージョン・ブランチを間違えていたためコメントアウトしました。 現状の master(3.9.0-rc.0) も同様に再現します。

kanreisa commented 2 years ago

ご報告ありがとうございます。 確認させていただきますが、多忙につき遅くなるかもしれません。 よろしくお願いいたします。

kanreisa commented 2 years ago

2e56d8d33e170ea1e1b95800587995321d35a6fe にて修正しました。リリース @3.9.0-rc.1 に適用されています。 ガイドラインに沿った記載をしていただいたおかげで、大変助かりました。 Windows Sandbox でインストールをテストしていますが、まだ直っていない場合は教えてください。

尚、Linux 環境の場合は root であっても --unsafe-perm を付けない限りは root で実行されないため、意図せずコマンドが実行されることはありませんでした。

どうぞよろしくお願いいたします。

yuta2k commented 2 years ago

上記の環境・操作にて、ローカルインストールが成功すること、 マニュアル記載の

npm install winser@1.0.3 -g
npm install mirakurun@latest -g --foreground-scripts --production

にて正常にグローバルインストールを行えることを確認しました。

Ubuntu/Linux の件は失礼しました。杞憂で良かったです。 とはいえ、例のグローバルインストールのチェック段階で止まるようになり、安全になったかなと思います。

早々のご対応ありがとうございました。 これからも愛用させていただきます🙂