NodeJs Package.json 无限递归依赖
NodeJs Package.json Infinite Recursive Dependency
这是我一直在思考的问题。 Node项目有没有可能遇到递归无限包依赖?我的意思是下面的。
假设主应用程序在 Package.json
的依赖部分中列出了包 A。反过来,假设这个包 A 依赖于一个包 B。也就是说,node_modules/A/Package.json
将在依赖部分包含 B。
现在,假设在一个疯狂的事件组合中,包 B 依赖于另一个包 C (C!= A),但是,该包具有 A 作为其依赖项。澄清一下,
node_modules/A/node_modules/B/package.json - contains C as dependency
node_modules/A/node_modules/B/node_modules/C/package.json - contains A as dependency
我的问题有两个方面。首先,这种情况在实践中甚至可能吗?其次,如何解决?在我看来,npm install
会发送此应用程序进行无限安装循环。
OP: Is it possible that a Node project may encounter a recursive and infinite package dependency?
没有
从 documented algorithm 开始,随着依赖关系树的遍历,"dependencies will be added as close to the top as is possible."
该页面上给出的示例说,如果您有一个包 A 依赖于包 B 和包 C,并且包 B 也依赖于包 C,则包 B 中的依赖项将通过副本解决已经为包 A 安装了。
因此,在您的示例中,主应用程序对 A 的依赖性将满足包 C 对 A 的依赖性。无需再次获取它。
然而,当您开始遇到依赖于不同版本的依赖项的依赖项时,事情会变得有点棘手。事实上,该页面上的 next section 专门讨论了这一点:
npm flat-out refuses to install any name@version that is already present anywhere in the tree of package folder ancestors
他们确实给了这个递归依赖安装的东西some thought。
这是我一直在思考的问题。 Node项目有没有可能遇到递归无限包依赖?我的意思是下面的。
假设主应用程序在 Package.json
的依赖部分中列出了包 A。反过来,假设这个包 A 依赖于一个包 B。也就是说,node_modules/A/Package.json
将在依赖部分包含 B。
现在,假设在一个疯狂的事件组合中,包 B 依赖于另一个包 C (C!= A),但是,该包具有 A 作为其依赖项。澄清一下,
node_modules/A/node_modules/B/package.json - contains C as dependency
node_modules/A/node_modules/B/node_modules/C/package.json - contains A as dependency
我的问题有两个方面。首先,这种情况在实践中甚至可能吗?其次,如何解决?在我看来,npm install
会发送此应用程序进行无限安装循环。
OP: Is it possible that a Node project may encounter a recursive and infinite package dependency?
没有
从 documented algorithm 开始,随着依赖关系树的遍历,"dependencies will be added as close to the top as is possible."
该页面上给出的示例说,如果您有一个包 A 依赖于包 B 和包 C,并且包 B 也依赖于包 C,则包 B 中的依赖项将通过副本解决已经为包 A 安装了。
因此,在您的示例中,主应用程序对 A 的依赖性将满足包 C 对 A 的依赖性。无需再次获取它。
然而,当您开始遇到依赖于不同版本的依赖项的依赖项时,事情会变得有点棘手。事实上,该页面上的 next section 专门讨论了这一点:
npm flat-out refuses to install any name@version that is already present anywhere in the tree of package folder ancestors
他们确实给了这个递归依赖安装的东西some thought。