npm - package.json 中的 phantomChildren 是什么?

标签 npm package yarnpkg package.json

当我安装模块时,phantomChildren 列表会出现在 package.json 文件中。什么是phantomChildren

最佳答案

我没有找到 npmphantomChildren 的官方文档。但遇到了一些其他的解释:https://rushjs.io/pages/advanced/phantom_deps/ 。它与 rast 相关,但很好地解释了 npm 依赖项的行为。

例如,库 A 可能会从库 BC 导入定义,但随后会导入 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/

相关文章:

reactjs - 如何将 CSS 与组件捆绑为 npm 包?

java - 包对象中的类型定义 "hijacking"scala代码中java类的继承

linux - 在 Raspberry Pi 上安装 Go 包

webpack - Node模块包如何导入依赖?

reactjs - serve -s build 指定端口号

node.js - 安装node和npm时出错

javascript - Cypress :找不到模块:错误:无法解析'cypress/types/lodash

node.js - 在 node.js 中,如何评估 excel 中包含对同一工作簿中其他工作表中单元格的引用的公式?

python - 如何构建 Python 包(?)以将文件添加到各个模块

node.js - Yarn似乎没有安装越来越少的 watch 编译器