[英]npm WARN install Refusing to install hapi as a dependency of itself
I tried to do the following (per instructions from official site ): 我尝试执行以下操作(根据官方网站的说明 ):
mkdir hapi && cd hapi
npm init
npm install hapi --save
But this gives me an error like this: 但这给了我一个这样的错误:
npm WARN install Refusing to install hapi as a dependency of itself
npm WARN安装拒绝安装hapi作为自身的依赖
Now, I made a new test folder called hapiTest
and repeated the commands and then everything worked fine. 现在,我创建了一个名为
hapiTest
的新测试文件夹并重复命令,然后一切正常。
I tried the same process with a folder gulp
and npm install gulp --save
, and got the same error, so my conclusion is that I can't have the name of the folder be the same as the package that I want to install, but can someone back this statement up with some official documentation? 我尝试使用文件夹
gulp
和npm install gulp --save
进行相同的过程,并得到相同的错误,所以我的结论是我不能让文件夹的名称与我要安装的包相同,但有人可以用一些官方文件支持这个声明吗?
When you did the command npm init
, there were probably some relevant questions you needed to answer. 当您执行命令
npm init
,可能需要回答一些相关问题。 Specifically, the name of your module. 具体来说,是模块的名称。 When you use
npm init
, it assumes you want the name of the module you're creating to be called the name of the folder it is in. 当您使用
npm init
,它假定您希望将要创建的模块的名称称为它所在的文件夹的名称。
So it's not the name of the folder that is stopping you from installing the dependency, it is the name of the npm module that you are creating. 因此,不是阻止您安装依赖项的文件夹的名称,它是您正在创建的npm模块的名称。
Open the resulting package.json
within your hapi
directory, and rename the module to something other than hapi
. 在
hapi
目录中打开生成的package.json
,并将模块重命名为hapi
其他内容。 Here's an example 'package.json' that works, even when residing in a folder called hapi : 这是一个有效的'package.json'示例,即使驻留在名为hapi的文件夹中也是如此:
{
"name": "hapi-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hapi": "^7.5.2"
}
}
Added Note 添加了注释
I've not been able to find any documentation thus-far explaining this phenomena in the context of npm; 我无法找到任何文件 - 远在npm的背景下解释这种现象; though it is a bit of a no-brainer.
虽然这有点不费吹灰之力。 Requiring modules with the same name within the same application would conflict with the CommonJS philosophy.
在同一个应用程序中要求具有相同名称的模块会与CommonJS理念发生冲突。
The name of your module is same as the module you are trying to install. 模块的名称与您尝试安装的模块相同。 NPM thinks that you are installing the module to itself.
NPM认为您正在将模块安装到自身。 Change the name of your module and it will install perfectly.
更改模块的名称,它将完美安装。
Reason Module name is same with library name 原因模块名称与库名称相同
Solution 解
The issue can be simply explained as follows the name of your package or module in package.json
cannot be same as that of the package or module you are trying to install . 问题可以简单解释如下:
package.json
中的包或模块的名称不能与您尝试安装的包或模块的名称相同 。
Here hapi
is the name of your module and you are trying to install a module with name hapi
with npm install hapi --save
这里
hapi
是你的模块的名称,你试图安装一个名为hapi
的模块,使用npm install hapi --save
This was my initial code 这是我的初始代码
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.6.1"
}
}
which threw error 这引起了错误
npm WARN package.json react@1.0.0 No description
npm WARN package.json react@1.0.0 No repository field.
npm WARN package.json react@1.0.0 No README data
npm WARN install Refusing to install react as a dependency of itself
then i renamed the name from react to react_app and my code looks like 然后我将名称从react更改为react_app,我的代码看起来像
{
"name": "react_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "^15.6.1"
}
}
then it worked 然后它奏效了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.