LoginSignup
3
1

More than 3 years have passed since last update.

npm installしたら「npm ERR! code ENOSELF」とか表示されたときの対処

Posted at

v10が公開 - ElectronでJS製デスクトップアプリを作ろうに興味を持ち、Electronを使ってデスクトップアプリを作ってみたいと思いました。

Node.jsインストール後、npm installしたところ、こんなエラー文が出たときの対処方法。

PS C:\electron> npm install electron
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "electron" under a package
npm ERR! also called "electron". 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!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2020-09-05T13_20_15_582Z-debug.log

原因

フォルダ名とパッケージ名が同じだとインストールができないとエラー分が主張していたからですね。
pakege.jsonでは"name": "electron"になっているので、ここを修正すれば解決できると考えられますね。

{
  "name": "electron", << "test"に修正した方がいい
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "electron index.js"
  },
  "keywords": [],
  "dependencies": {
    "electron": "^10.1.1"
  }
}

解決策

  • プロジェクト名をtestへ修正。
  • pakege.jsonには "name": "test"へ修正。

自分の場合、プロジェクト名を「electron」と適当に付けてしまったのでそれ以外の名前を付けないといけないので、プロジェクト名を「test」に変更。そのままインストールしてもpakege.jsonも変更されていなければできないので、そこも修正。

その結果、インストール成功しました!!

プロジェクト名を決めるときは無難に「test」つけた方がよかったですね(^^;

ではまた!

参考サイト

npm install をしたら「npm ERR! code ENOSELF npm ERR! Refusing to install package with name "gulp" under a package」みたいに怒られたとき

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