简体   繁体   English

在快速项目的package.json中添加依赖项

[英]Adding dependencies in package.json of an express project

Assume the following scenario. 假定以下情况。 Suppose I am developing an express project named test . 假设我正在开发一个名为test的快递项目。 In that project I am using a node module named x . 在该项目中,我正在使用名为x的节点模块。 x uses another module named y . x使用另一个名为y模块。 I have already added x to the dependencies of package.json of project test . 我已经将x添加到项目testpackage.json的依赖项中。 Do I need to add y too? 我也需要添加y吗? Simple intuition says I don't need to but it's causing me problem. 简单的直觉说我不需要,但是这给我带来了麻烦。 Any help? 有什么帮助吗?

To answer your question, yes you need to add y . 要回答您的问题,是的,您需要添加y From what I understand, it works the other way around. 据我了解,它反过来起作用。 If you have y already installed as your projects dependency, x won't need to install it as its dependency. 如果您已经安装了y作为您的项目依赖项,则x不需要安装它作为其依赖项。

Node looks at the upper level directories (before looking at the current directory) if there are present node_modules folders, and searches them if the module you are looking for is already present. 如果存在node_modules文件夹,Node会查看上一级目录(在查看当前目录之前),如果正在寻找的模块已经存在, node_modules搜索它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM