在节点模块中需要另一个依赖关系的依赖关系 [英] Require dependency of another dependency in node modules

查看:64
本文介绍了在节点模块中需要另一个依赖关系的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的节点应用程序,该应用程序对github上另一个应用程序具有单一依赖性. npm install可以很好地安装依赖项,但是当我尝试在其中安装某些东西时,它说它不可用.例如,github应用程序将Mongoose安装为依赖项.我认为该父应用程序可以访问该模块,因为它位于子模块中:

I've got a simple node app that has single dependency on another app on github. The dependency installs just fine with npm install, but when I try to require something installed there, it says it's not available. For example, the github app installs Mongoose as a dependency. I thought that this parent app would be able to access that module since it is in a child:

var mongoose = require('mongoose')

结构看起来像这样:

/app
  /node_modules
    /github_dependency [parent module]
      /node_modules
        /mongoose [child module]

我是否只需要在父级应用程序中也包含猫鼬作为依赖项,或者是否可以通过子级方式访问该模块?

Do I just have to include mongoose as a dependency as well in the parent app or is there a way of getting access to that module by way of the child?

推荐答案

我是否只需要在父级应用程序中也包含猫鼬作为依赖项,或者是否可以通过子级方式访问该模块?

Do I just have to include mongoose as a dependency as well in the parent app or is there a way of getting access to that module by way of the child?

虽然您可能 require('github/node_modules/mongoose'),标准做法是显式安装所有依赖项(即,应将mongoose作为应用程序的依赖项)和require('mongoose').

While it's possible for you to e.g. require('github/node_modules/mongoose'), the standard practice is to install all of your dependencies explicitly (i.e., you should include mongoose as a dependency of your app) and require('mongoose').

这篇关于在节点模块中需要另一个依赖关系的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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