Windows 10にnode.js 7.0.0をインストールしたらnpm install が「Cannot find module 'internal/fs'」エラーでコケる件

公開:2016-10-26 21:26
更新:2020-02-15 04:37
カテゴリ:node.js

7.0.0をインストールして「npm install electron -g」しようとしたらエラー発生。

C:\WINDOWS\system32>npm install electron -g
npm ERR! Windows_NT 10.0.14955
npm ERR! argv "I:\\App\\nodejs\\node.exe" "i:\\libs\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "electron" "-g"
npm ERR! node v7.0.0
npm ERR! npm  v3.3.10
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'internal/fs'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     C:\WINDOWS\system32\npm-debug.log

うーむ。ビルトインのfsが見つからないというものすごいエラーだ。issueを見ると上がっていた。

https://github.com/npm/npm/issues/14232

原因はどうも私がnpmを適切なバージョンにアップグレードしていなかったかららしい。

You're going to need to upgrade to npm@3.10.9 (currently npm@next – npm -g install npm@next if you have it installed globally, npm-windows-upgrade to make it easier on Windows), because there's a backwards-incompatible change made to Node's internals that require a newer version of graceful-fs, a utility package heavily used by the npm CLI. Thanks for your time!

npm-windows-upgradeをインストールすれば簡単にできると書いてあるのでインストールしようとしたら、npmが動かないので当然インストールできない。 しょうがないので、1つまえの6.9.1に戻して、npm-windows-upgradeで4.0.1にアップグレードした後、7.0.0をインストールしたらこの問題は解決した。

https://www.npmjs.com/package/npm-windows-upgrade

そういえばいつのころからか、npmを使うとfsに関するワーニングが出ていたような気がしたな。。

いずれにせよ解決してよかった。。