我有一个简单的 Node 应用程序,它依赖于 github 上的另一个应用程序。使用 npm install
可以很好地安装依赖项,但是当我尝试要求在那里安装某些东西时,它说它不可用。例如,github 应用程序将 Mongoose 作为依赖项安装。我认为这个父应用程序将能够访问该模块,因为它在一个 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(' Mongoose ')
.
关于node.js - 需要依赖 Node 模块中的另一个依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9736514/