LoginSignup
48

More than 3 years have passed since last update.

Windows10にてNode環境構築によくあるエラー

Last updated at Posted at 2019-05-28

Node.jsの環境構築はLinuxでは問題なく一発で完了できるのはほとんどですが、
Windows10のOSだと、よくエラーが発生し、回避しないと先に進まないケースもあります。
・node-gypにてコンパイルエラー
・Nodeのバージョンが高すぎる問題
・npm ERR! git xxx

node-gypにてコンパイルエラー

Node.jsではすべてJavaScriptで実現したのではなく、C++を利用している部分がありました。
C++を利用すると、C++コンパイルツールが必要です。

https://github.com/nodejs/node-gyp
にて2つのやり方は紹介されました。

案1:windows-build-tools

PowerShellを管理者権限で起動し、下記のコマンドを発行する
npm install --global --production windows-build-tools

ネットの記事を探してもこの案で回避できたという記載が多いです。
残念ながら、私の環境では何度も試してもエラーが解消しませんでした。

案2:Visual Studio Build Tools

①、Visual C++ ビルド環境のインストール 
 インストール方法は2つあります。
 方法1:BuildToolsをダウンロードしてインストール ※こちらのほうが楽です。
   https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools

   ※2015バージョンが欲しい場合はMSBuild2015をダウンロードしてインストール
   https://go.microsoft.com/fwlink/?LinkId=691126

 方法2:Visual Studio 2017 Community をインストール

②、Python 2.7をインストール
 下記のURLのからダウンロードしてインストール。※Python 3.x.xはサポートされません。
 https://www.python.org/downloads/release/python-2715/
 

③、npm設定を行う。2017はインストールしたバージョンです。BuildTools2015の場合は「2015」でセット
 npm config set python python2.7
 npm config set msvs_version 2017

これでコンパイルエラーがは解消できました。

Nodeのバージョンが高すぎる問題

たまにNodeのバージョンが高すぎる問題がありました。
その際にはDowngradeする対応は多いでしょう
nodistツールでバージョン管理でも楽です。
https://github.com/marcelklehr/nodist/releases

インストール後、Pathに追加し、PowerShellから実行できるように。
必要なバージョンを指定すると簡単に切り替えできます。
nodist -vコマンドでNodistのバージョン確認できます。
node -vコマンドでNodeのバージョン確認できます。
nodist distコマンドでインストール可能なNodeバージョンリスト確認できます。
nodist 8.16.0のようにバージョンを指定してNodeを切り替えできます。

npm ERR! git xxx

初回目のnpm install にて問題なかったですが、2回目以降は、下記のようなエラーが発生する場合もあります。

npm ERR! path xxxxxx\node_modules\web3-providers-ws\node_modules\websocket
npm ERR! code EISGIT
npm ERR! git xxxxxx\node_modules\web3-providers-ws\node_modules\websocket: Appears to be a git repo or submodule.npm ERR! git xxxxxx\node_modules\web3-providers-ws\node_modules\websocketnpm ERR! git Refusing to remove it. Update manually,npm ERR! git or move it out of the way first.

このエラーの場合は乱暴的な解決方法として、node_modulesフォルダーをまるごと削除し、npm install で再インストールします。

以上

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
48