LoginSignup
2
0

More than 5 years have passed since last update.

Node.js v11.0.0でElectronウィンドウが表示されない

Last updated at Posted at 2018-10-30

こんにちわ。

Node.jsをv10.2.0 -> v11.0.0に更新したのですが、そしたらElectronがコケるようになってしまいました。

事象

CommandPrompt
> node -v
v11.0.0

> electron
Electron 4.0.0-beta.5 - Build cross platform desktop apps with JavaScript, HTML,
 and CSS
Usage: electron [options] [path]

A path to an Electron app may be specified. It must be one of the following:
  - index.js file.
  - Folder containing a package.json file.
  - Folder containing an index.js file.
  - .html/.htm file.
  - http://, https://, or file:// URL.

Options:
  -i, --interactive     Open a REPL to the main process.
  -r, --require         Module to preload (option can be repeated).
  -v, --version         Print the version.
  -a, --abi             Print the Node ABI version.

この後、CMDウィンドウからフォーカスは外れるのですが、いくら待っても何も起きません。

原因

結論から言うと、v11.0.0からchild_process.spawn()のウィンドウ表示オプションが、デフォルトで非表示モードになってしまった事によります。

Electron起動スクリプトでchild_process.spawn()が走った際、非表示で実行されてしまう、と言った至極単純な原因でした。

どうりで、プロセス自体は元気に動いてるしエラーログも出ない訳だ...

[History]
v11.0.0
The windowsHide option now defaults to true.

解説

ターミナルからElectronを起動すると、以下のような段階を踏んで、実体のelectron.exeに辿り着きます。

> electron
 node_module/electron.cmd
   node_modules/electron/cli.js
     node_modules/electron/dist/electron.exe

cli.jsに注目。

node_modules/electron/cli.js
#!/usr/bin/env node

var electron = require('./')

var proc = require('child_process')

var child = proc.spawn(electron, process.argv.slice(2), { stdio: 'inherit' })
child.on('close', function (code) {
  process.exit(code)
})

const handleTerminationSignal = function (signal) {
  process.on(signal, function signalHandler () {
    if (!child.killed) {
      child.kill(signal)
    }
  })
}

handleTerminationSignal('SIGINT')
handleTerminationSignal('SIGTERM')

proc.spawn()のオプションに表示モード指定がありませんね。
これだと非表示モードになってしまいます。

解決策(暫定)

node_modules/electron/cli.js
var child = proc.spawn(electron, process.argv.slice(2), { stdio: 'inherit', windowsHide: false })

表示モードを指定するだけ。

愚痴

こんな原因の為に丸1日費やしてしまったよ!!!

-> GitHubに Issue 出しときました。速攻でプルリク出してくれたので次のリリースで修正されると思います。感謝感激。

2
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
2
0