---
lang: ja-jp
breaks: true
---
# Node.jsのパッケージ管理ツール「npm」(Node Packaged Modules)を使用して、Electronをインストールする。Windows10 2021-04-08
### Electronをインストールする-1(※失敗)
>Electronをインストールする際は、先ほどインストールしたNode.jsのパッケージ管理ツール「npm」(Node Packaged Modules)を使用します。
>https://www.pc-koubou.jp/magazine/23739
```
>npm install -g electron
npm WARN npm npm does not support Node.js v14.16.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11, 12.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxxxx\AppData\Roaming\npm-cache\_logs\2021-04-08T03_00_13_589Z-debug.log
```
> npm WARN npm サポートしているNode.jsのリリースは、6、8、9、10、11、12の最新リリースです。
とのことなので、12の最新バージョンに入れ替える。
https://hackmd.io/4nR8p3cSQ4msfkL7_CUmEQ
### Electronを再度インストールする
```
>npm install -g electron
npm ERR! cb.apply is not a function
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxxxx\AppData\Roaming\npm-cache\_logs\2021-04-08T04_22_22_616Z-debug.log
```
再度エラーとなった。
ログファイル
```=
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files (x86)\\Nodist\\v-x64\\12.22.1\\node.exe',
1 verbose cli 'C:\\Program Files (x86)\\Nodist\\npmv\\6.9.0\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli 'electron'
1 verbose cli ]
2 info using npm@6.9.0
3 info using node@v12.22.1
4 verbose npm-session a4a18a7394fae551
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 200 https://registry.npmjs.org/electron 14ms (from cache)
8 silly pacote tag manifest for electron@latest fetched in 32ms
9 verbose stack TypeError: cb.apply is not a function
9 verbose stack at C:\Program Files (x86)\Nodist\npmv\6.9.0\node_modules\graceful-fs\polyfills.js:285:20
9 verbose stack at FSReqCallback.oncomplete (fs.js:169:5)
10 verbose cwd C:\Users\xxxxx
11 verbose Windows_NT 10.0.17763
12 verbose argv "C:\\Program Files (x86)\\Nodist\\v-x64\\12.22.1\\node.exe" "C:\\Program Files (x86)\\Nodist\\npmv\\6.9.0\\bin\\npm-cli.js" "install" "-g" "electron"
13 verbose node v12.22.1
14 verbose npm v6.9.0
15 error cb.apply is not a function
16 verbose exit [ 1, true ]
```
> いろいろ調べるとnodistやめてピュアにインストールしろなどのものがありますが、そもそもこのエラーが出るのは単にnpmがnodeとのバージョンで不整合がおきてるからです。
なので、npmを最新にしましょう!
> その場合は以下のようにnodist経由でnpmのバージョンを変更すると解決します。
>https://qiita.com/wakasamasao/items/6a39ff36e448dd6d7d36
```
>nodist npm 6.14.11
npm 6.14.11
https://codeload.github.com/npm/cli/tar.gz/v6.14.11 [============ ] 4533/5831 KiB 77% 12.9s
```
### 再度、Electronをインストールする-2
```
>npm install -g electron
C:\Program Files (x86)\Nodist\bin\electron -> C:\Program Files (x86)\Nodist\bin\node_modules\electron\cli.js
npm WARN lifecycle The node binary used for scripts is C:\Program Files (x86)\Nodist\bin\node.exe but npm is using C:\Program Files (x86)\Nodist\v-x64\12.22.1\node.exe itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.
> core-js@3.10.1 postinstall C:\Program Files (x86)\Nodist\bin\node_modules\electron\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock
Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
> electron@12.0.2 postinstall C:\Program Files (x86)\Nodist\bin\node_modules\electron
> node install.js
Downloading electron-v12.0.2-win32-x64.zip: [==================================================] 100% ETA: 0.0 seconds
+ electron@12.0.2
added 87 packages from 96 contributors in 190.856s
```
インストールされたバージョンを確認
```
>electron -v
v12.0.2
```
electronを起動してみる。
```
>electron
Electron 12.0.2 - 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.
```

やっと成功した!!
###### tags: `Electron` `nodist` `Node.js` `npm` `Windows 10`