当我安装模块时,phantomChildren
列表会出现在 package.json
文件中。什么是phantomChildren
?
最佳答案
我没有找到 npm
包 phantomChildren
的官方文档。但遇到了一些其他的解释:https://rushjs.io/pages/advanced/phantom_deps/ 。它与 rast
相关,但很好地解释了 npm
依赖项的行为。
例如,库 A
可能会从库 B
和 C
导入定义,但随后会导入 B
和 >C
都可以从 D
导入,这在这四个包之间创建了“钻石依赖关系”。
A “phantom dependency” occurs when a project uses a package that is not defined in its
package.json
file.
一些实例:
my-library/package.json
{
"name": "my-library",
"version": "1.0.0",
"main": "lib/index.js",
"dependencies": {
"minimatch": "^3.0.4"
},
"devDependencies": {
"rimraf": "^2.6.2"
}
}
my-library/lib/index.js
var minimatch = require("minimatch")
var expand = require("brace-expansion"); // ???
var glob = require("glob") // ???
Wait a sec – two of these libraries are not declared as dependencies in the package.json file. How is this working at all!? It turns out that brace-expansion is a dependency of minimatch, and glob is a dependency of rimraf. During installation, NPM has flattened their folders to be under my-library/node_modules. The NodeJS require() function finds them there because it probes for folders without considering the package.json files at all.
总结:如果包使用其自身依赖项的依赖项,则可以将其视为 phantomChildren。包不直接具有此类依赖项,而是从其他地方使用它。
关于npm - package.json 中的 phantomChildren 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56837043/