LoginSignup
172
171

More than 5 years have passed since last update.

npm トラブルシューティング

Last updated at Posted at 2016-08-31

自分が遭遇したエラーとその解決方法をまとめました。

随時更新予定(最近エラーに遭遇してないので更新止まってます。)

逆引き 編

install が途中で止まる

以下のいずれかを実行する。

npm をアップグレードする

$ npm install -g npm

npm のキャッシュをクリアする

$ rm -rf node_modules
$ npm cache clean
$ npm install

sudo をつける

$ sudo npm install

--no-bin-links フラグを付ける

$ npm install --no-bin-links

これらのいずれかで解決するはず。
特に, 普段 npm install --save hoge 等で errno -71 が吐かれる場合は, --no-bin-links で解決。
主にシンボリックリンクが貼れない Windows 環境で発生する。
詳細は、Error No.71 を参照。

解決できない場合
特に, どこかからかコピペしてきた package.json 実行時などは, 解決しない時がある. 常に同じパッケージで止まる場合, そのパッケージを package.json から削除する.
個別で install するか, 代替を探す

npm install -g fsevents が失敗する

npm の公式に issue として多数報告されているが、今のところ解決方法なし?(2016/9/5現在)
npm 3系で起きるっぽい
参考ページ


Error No. 編

Error No.2

発生例
> npm ERR! npm  v3.10.6
> npm ERR! path /vagrant/www/angular2-quickstart/node_modules/typescript/bin/tsc
> npm ERR! code ENOENT
> npm ERR! errno -2
> npm ERR! syscall chmod

ファイルの実行権限がない時のエラー
chmod +x node_modules/ -R 実行
もしくは, sudo をつけて実行

Error No.3

発生例
$ npm install hoge
> npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules'
> npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules']
> npm ERR!   errno: 3,
> npm ERR!   code: 'EACCES',
> npm ERR!   path: '/usr/local/lib/node_modules',
> npm ERR!   fstream_type: 'Directory',
> npm ERR!   fstream_path: '/usr/local/lib/node_modules/npm',
> npm ERR!   fstream_class: 'DirWriter',
> npm ERR!   fstream_stack:
> npm ERR!    [ '/usr/lib/nodejs/fstream/lib/writer.js:171:23',
> npm ERR!      '/usr/lib/nodejs/mkdirp/index.js:37:53',
> npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
> npm ERR!
> npm ERR! Please try running this command again as root/Administrator.

書き込み権限が無い時のエラー
sudo をつけて実行で解決

Error No.13

発生例
$ npm cache clean
> npm ERR! Linux 3.13.0-95-generic
> npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "cache" "clean"
> npm ERR! node v6.5.0
> npm ERR! npm  v3.10.3
> npm ERR! path /home/hoge/.npm/registry.npmjs.org/Base64
> npm ERR! code EACCES
> npm ERR! errno -13
> npm ERR! syscall rmdir
>
> npm ERR! Error: EACCES: permission denied, rmdir '/home/hoge/.npm/registry.npmjs.org/Base64'
> npm ERR!     at Error (native)
> npm ERR!  { Error: EACCES: permission denied, rmdir '/home/vagrant/.npm/registry.npmjs.org/Base64'
> npm ERR!     at Error (native)
> npm ERR!   errno: -13,
> npm ERR!   code: 'EACCES',
> npm ERR!   syscall: 'rmdir',
> npm ERR!   path: '/home/vagrant/.npm/registry.npmjs.org/Base64' }
> npm ERR!
> npm ERR! Please try running this command again as root/Administrator.
>
> npm ERR! Please include the following file with any support request:
> npm ERR!     /vagrant/www/npm-debug.log

.npm ディレクトリの所有権がカレントユーザと異なる時のエラー
sudoをつけて npm install を実行後, npm cache clean を実行しようとすると起こる

sudo chown -R $(whoami) "$HOME/.npm" を実行で解決

Error No.31

発生例
$ npm run hoge
> npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
> npm ERR!     at Error (native)
> npm ERR!  { Error: EACCES: permission denied, access '/usr/lib/node_modules'
> npm ERR!     at Error (native)
> npm ERR!   errno: -13,
> npm ERR!   code: 'EACCES',
> npm ERR!   syscall: 'access',
> npm ERR!   path: '/usr/lib/node_modules' }
> npm ERR!
> npm ERR! Please try running this command again as root/Administrator.

アクセス権限がない時のエラー
sudo をつけて実行、もしくは chmod で権限を付与する。

Error No.71

発生例
$ npm install --save hoge
> npm ERR! Linux 3.13.0-95-generic
> npm ERR! argv "/hoge" "/huga" "install" "--save" "react" "react-dom"
> npm ERR! node v6.5.0
> npm ERR! npm  v3.10.3
> npm ERR! path ../loose-envify/cli.js
> npm ERR! code EPROTO
> npm ERR! errno -71
> npm ERR! syscall symlink
>
> npm ERR! EPROTO: protocol error, symlink '../loose-envify/cli.js' -> '/node_modules/.bin/loose-envify'
> 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!     /vagrant/www/js/npm-debug.log

npm install hoge --no-bin-links とすることで解決
Linux 環境下かつ、Windows と共有しているフォルダ上で実行しようとしてよく発生する(自分の場合は Vagrant の共有フォルダ)。
原因は、インストール時にシンボリックリンクを作成するから。
--no-bin-links を指定することで、シンボリックリンクを作成せずにインストールする。
しかし、このオプションを指定しても違うエラーで失敗する可能性がある。
npm でのパッケージインストールは、Windows 側から行うか、共有フォルダ外で実行すべき。


Exit status 編

Exit status 137

発生例
$ npm run build
> js@1.0.0 build /vagrant/www
> webpack --config webpack-production.config.js --progress --colors
>
>  78% additional chunk assetsKilled
>
> npm ERR! Linux 3.13.0-95-generic
> npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "run" "build"
> npm ERR! node v6.5.0
> npm ERR! npm  v3.10.3
> npm ERR! code ELIFECYCLE
> npm ERR! js@1.0.0 build: `webpack --config webpack-> production.config.js --progress --colors`
> npm ERR! Exit status 137

主に, 仮想マシンの RAM の不足で起きるらしい
RAM の容量を増やすことで解決
RAM が原因じゃない場合は, npm set strict-ssl false 実行で解決するかも

172
171
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
172
171