问题描述
我使用 node.js 编写了一个简单的应用程序.这取决于 express、mongodb 和 mongoose(简单).因此,我创建了一个名为 package.json
的文件并将其放入其中:
I wrote a simple application using node. It depends on express, mongodb and mongoose (easy).So, I created a file called package.json
and put this in it:
{
"name": "booking-dojo",
"description": "Booking dojo app",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x",
"mongodb": "*",
"mongoose": "*"
}
}
然后我运行 npm install
,期望 npm 安装这些模块和它们的依赖项.结果令人失望:
I then ran npm install
, expecting npm to install those modules and their dependencies.The result was disappointing:
[email protected] /home/merc/Synced/Development/Bookings/app/server
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
└── [email protected]
我对此感到困惑,因为我知道express
需要jade
(以及更多)和mongoose
需要 mongodb
.
如果我进入 node_modules/jade
并运行 npm install
,主树的结果非常不同:
I am confused by this, as I know that express
needs jade
(and much more), and mongoose
needs mongodb
.
If I go into node_modules/jade
and run npm install
, the result from the main tree is very different:
[email protected] /home/merc/Synced/Development/Bookings/app/server
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
├── [email protected]
└── [email protected]
所以,express
成长很多.看起来npm install
只是加载一些 子模块的依赖项.
So, express
has grown a lot. It looks like npm install
is only loading some of the dependencies of the sub-modules.
有人可以对此有所了解吗?为什么缺少某些依赖项?难道我做错了什么?(可能)
Can somebody please shed some light on this? Why are some dependencies missing? Am I doing something wrong? (likely)
谢谢!
佣兵.
推荐答案
答案由 Brandon 在对另一个答案的评论中提供:
The answer was provided by Brandon in a comment to another answer:
"另一件需要注意的事情是,如果一个包依赖一个可以在依赖链中进一步解析的模块,它会.例如,因为你的 package.json 中有 mongodb,Mongoose 不需要安装自己的 mongodb. – Brandon Tilley 2 天前
"Another thing to note is that if a package depends on a module that can be resolved further up in the dependency chain, it will. For example, since you have mongodb in your package.json, Mongoose doesn't need to install its own mongodb. – Brandon Tilley 2 days ago
谢谢布兰登!(这就是答案...)
Thank you Brandon! (And this is the answer...)
这篇关于如何编写 package.json 文件,以便使用“npm install"下载所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!