问题描述
我有一个简单的节点应用程序,它只依赖于 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]
我是否只需要将 mongoose 作为依赖项也包含在父应用程序中,或者是否有办法通过子应用程序访问该模块?
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('猫鼬')
.
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')
.
这篇关于需要节点模块中另一个依赖项的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!