3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

package.jsonのnameと同名のパッケージはインストール時に拒否される

Posted at

ちょっと考えたら至極当たり前な挙動なのですが、先日うっかりやらかしたので。

npm initを使って対話形式で新規パッケージを作成する際に、nameと同名のパッケージはインストールできません。
使いたいパッケージ名と重複しないようにnameを指定しておく必要があります。

package.json
{
  "name": "gulp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

terminal
$ npm install --save-dev gulp
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "gulp" under a package
npm ERR! also called "gulp". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR! 
npm ERR! For more information, see:
npm ERR!     <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/hoge/.npm/_logs/2018-09-30T05_24_34_882Z-debug.log

--forceフラグの指定で強制的にインストールすることもできますが、そこまでインストールするよりパッケージのname値を変えてしまうほうが圧倒的に早いと公式にも記載がありました。ちゃんと読まないとだめですね…。

3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?