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

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

Answer

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": {
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *