急いでる人のための結論
エラーログに
npm ERR! Failed to parse json npm ERR! Unexpected token }
とあったら、package.jsonの末尾に余計なカンマが入ってます。
ちゃんと閉じましょう。
ことのあらまし
express4から、express3に入っていたパッケージの内かなりの部分が外部化しました。
その流れで、basic-auth-connectを導入しようとしたところ……
$ npm install basic-auth-connect npm ERR! Darwin 14.1.0 npm ERR! argv "/Users/shuzo_kino/.anyenv/envs/ndenv/versions/v0.12.0/bin/node" "/Users/shuzo_kino/.anyenv/envs/ndenv/versions/v0.12.0/bin/npm" "install" "basic-auth-connect" npm ERR! node v0.12.0 npm ERR! npm v2.5.1 npm ERR! file /Users/shuzo_kino/node/basicAuth/package.json npm ERR! code EJSONPARSE npm ERR! Failed to parse json npm ERR! Unexpected token } npm ERR! File: /Users/shuzo_kino/node/basicAuth/package.json npm ERR! Failed to parse package.json data. npm ERR! package.json must be actual JSON, not just JavaScript. npm ERR! npm ERR! This is not a bug in npm. npm ERR! Tell the package author to fix their package.json file. JSON.parse npm ERR! Please include the following file with any support request: npm ERR! /Users/shuzo_kino/node/basicAuth/npm-debug.log
エ、ナンデ!?
さっきまで大丈夫だったのに!?
で、何が起こってたのさ
出、出〜〜wwww package.json内のタイポで30分無駄にし奴wwww
— 木野修造 (@shuzo_kino) 2015, 6月 13
……はい、そうです。
npm installなどのコマンドで活用するpackage.jsonにタイポがあったのです。
具体的には、
{ "foge" : "*", "fuga" : "0.0.1", // <= 犯人 }
はい。高級スクリプトならともかく、末尾のカンマは無効です。
npm ERR! Failed to parse json npm ERR! Unexpected token }
という文句で気付くべきでしたね。