npm WARN install 拒绝安装 hapi 作为自身的依赖 [英] npm WARN install Refusing to install hapi as a dependency of itself

查看:96
本文介绍了npm WARN install 拒绝安装 hapi 作为自身的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行以下操作(根据官方网站的说明):

I tried to do the following (per instructions from official site):

  • mkdir hapi &&cd hapi
  • npm 初始化
  • npm install hapi --save

但这给了我这样的错误:

But this gives me an error like this:

npm WARN install 拒绝安装 hapi 作为自身的依赖

npm WARN install Refusing to install hapi as a dependency of itself

现在,我创建了一个名为 hapiTest 的新测试文件夹并重复这些命令,然后一切正常.

Now, I made a new test folder called hapiTest and repeated the commands and then everything worked fine.

我对文件夹 gulpnpm install gulp --save 尝试了相同的过程,并得到了相同的错误,所以我的结论是我不能文件夹的名称与我要安装的包的名称相同,但有人可以用一些官方文档支持此声明吗?

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?

推荐答案

当您执行命令 npm init 时,您可能需要回答一些相关问题.具体来说,就是您的模块的名称.当您使用 npm init 时,它假定您希望正在创建的模块的名称被称为它所在文件夹的名称.

When you did the command npm init, there were probably some relevant questions you needed to answer. 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 模块的名称em> 你正在创造.

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.

在您的 hapi 目录中打开生成的 package.json,并将模块重命名为 hapi 以外的其他名称.这是一个即使位于名为 hapi 的文件夹中也能正常工作的package.json"示例:

Open the resulting package.json within your hapi directory, and rename the module to something other than hapi. Here's an example 'package.json' that works, even when residing in a folder called 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"
  }
}

添加注释

到目前为止,我还没有找到任何文档在 npm 的上下文中解释这种现象;虽然这有点不费吹灰之力.在同一应用程序中要求具有相同名称的模块会与 CommonJS 理念相冲突.

I've not been able to find any documentation thus-far explaining this phenomena in the context of 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.

这篇关于npm WARN install 拒绝安装 hapi 作为自身的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆