nodejs使用npm + package.json解析依赖关系

Tam*_*mil 4 node.js npm

我的项目结构如下

 /
    index.js
    package.json
    node_modules
    |_Service_A
      |__main.js
      |__package.json
    |_Service_B
      |__main.js
      |__package.json
Run Code Online (Sandbox Code Playgroud)

当我npm install在项目根目录上执行时,解决了/package.json中提到的依赖项,但没有解析node_modules/Service_A/package.json或node_modules/Service_B/package.json中的依赖项.如何让npm解决不同文件夹之间的依赖关系?

Service_A和Service_B是我在node_modules中预加载的本地模块[它们具有依赖关系].我知道我可以接受它们的依赖并将它们放在顶层json中,但是如果它们依赖于相同的模块但不同的版本会怎样.例如:Service_A需要jquery 1.6和Service_B jquery 1.7吗?

net*_*ead 7

由于Service_A和Service_B是本地模块,我假设您没有在顶级package.json dependecies部分中定义.所以npm不知道它们甚至存在.

考虑在git存储库下开发本地模块,然后您可以通过以下方式定义它们:

"dependencies": {
  "public": "git://github.com/user/repo.git#ref", 
  "private": "git+ssh://git@github.com:user/repo.git#ref"
}
Run Code Online (Sandbox Code Playgroud)