Infinity
Infinity

Reputation: 441

npm ERR Refusing to install package with name <packageName> under a package also called <packageName>

I am trying to use the jsonfile package in my project, but I get the following errors:

  1. Refusing to install package with name <packagename> under a package also called <packagename>. (Note that none of the directory or filename is same as package name)

  2. Cannot find module <packagename>.

enter image description here

enter image description here

Upvotes: 20

Views: 16940

Answers (2)

Thao Nguyen Tien
Thao Nguyen Tien

Reputation: 869

The problem is caused when the name of project in package.json is the same as the module you're trying to install.

To solve this problem, please change the project name in package.json to something else. For example, "jsonfile-test":

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

Upvotes: 54

Chris Campbell
Chris Campbell

Reputation: 313

I think it should be:

npm install --save json-file

not

npm install --save jsonfile

ref: https://www.npmjs.com/package/json-file

If that does not work please try enabling permissions install - e.g. (on mac- but will be equivalent on windows, check: https://helpdeskgeek.com/free-tools-review/5-windows-alternatives-linux-sudo-command/) run:

sudo npm install --save json-file

Upvotes: -1

Related Questions