我的项目结构如下
/
index.js
package.json
node_modules
|_Service_A
|__main.js
|__package.json
|_Service_B
|__main.js
|__package.json
当我做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?
由于 Service_A 和 Service_B 是本地模块,我假设它们没有在顶级 package.json 依赖项部分中定义。所以 npm 甚至不知道它们的存在。
考虑在 git 存储库下开发本地模块,然后您可以通过以下方式定义它们:
"dependencies": {
"public": "git://github.com/user/repo.git#ref",
"private": "git+ssh://[email protected] /cdn-cgi/l/email-protection:user/repo.git#ref"
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)