The Node Package Manager (NPM) seems to yield duplicated packages

后端 未结 1 1905
[愿得一人]
[愿得一人] 2021-01-18 19:10

I\'ve been installing a few node packages and what I noticed is that NPM creates a bunch of duplicates.

For example, I first installed mongoose, which installed a bu

相关标签:
1条回答
  • 2021-01-18 19:55

    The problem is when mongoose is only coded to work with say v1 of mongodb, and you've coded your app to work with v2 of mongodb - as such, it installs and loads up both versions so it all works. We can do this easily in node, as the require module way doesn't pollute the global namespace, unlike the browser - which makes managing and including the right dependencies a royal pain due the global namespace pollution.

    Now if your package.json and mongoose's package.json allow the same mongodb version (your can specify a specific version or ranges), then doing a rm -Rf node_modules; npm install will only install one copy of mongodb, rather than two. However as said before, if multiple versions are specified, multiple versions will be installed and loaded.

    0 讨论(0)
提交回复
热议问题