Gulp のインストールでエラーが出た
Gulpを使って開発をしようとしたら、 $ npm install gulp --save-dev
でエラーがでたので、メモ。
どういうこと?
ローカルでGulpを使って開発をしようとしました。 Gulpを使うのが久しぶりだったので、以下の記事を参考にGulpを設定しようとしました。
$ npm init
$ npm install gulp -g
までは問題なく出来ましたが、$ npm install gulp --save-dev
でエラーを吐いて進まなくなりました。
$ pwd /Volumes/MacintochHD/Documents/ $ mkdir gulp $ cd gulp $ npm init npm init This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. name: (gulp) version: (1.0.0) description: entry point: (index.js) test command: git repository: keywords: author: license: (ISC) About to write to /Volumes/MacintochHD/Documents/gulp/package.json: { "name": "gulp", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" } $ npm install gulp -g $ npm install gulp --save-dev npm ERR! Darwin 14.5.0 npm ERR! argv "/usr/local/Cellar/node/6.7.0/bin/node" "/usr/local/bin/npm" "install" "gulp" "--save-dev" npm ERR! node v6.7.0 npm ERR! npm v3.10.8 npm ERR! code ENOSELF npm ERR! Refusing to install gulp as a dependency of itself 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! /Volumes/MacintochHD/Documents/gulp/npm-debug.log
うーん、どういうことだろう?
原因はpackage.jsonのnameでした。
どうやら、開発用に用意したディレクトリ名が"gulp"だったのが問題らしい。
package.jsonのnameはデフォルトでディレクトリ名を取るらしく、それがgulpだとエラーになるらしい。
なので、package.jsonを修正する。
{ "name": "gulptest", <= gulpから変更 "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "devDependencies": { "gulp": "^3.9.1" } }
この状態で再度 $ npm install gulp --save-dev
を実行すると、問題なくインストールできました。
以前、hubotでも同じエラーがあったなぁ。npmだとpackage名と同じ名前をpackage.jsonのnameに指定するとエラーになるみたい。 あとでもうちょっと調べてみよう。