Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are phantomChildren in package.json?

When I install a module, a list of phantomChildren appears in the package.json file. What are phantomChildren?

like image 546
lane Avatar asked Jul 01 '19 14:07

lane


People also ask

What are Peerdependencies in package json?

Peer dependencies are a special type of dependency that would only ever come up if you were publishing your own package. Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package.

What does package json contain?

Your package. json holds important information about the project. It contains human-readable metadata about the project (like the project name and description) as well as functional metadata like the package version number and a list of dependencies required by the application.

What are scripts in package json?

Scripts are stored in a project's package. json file, which means they're shared amongst everyone using the codebase. They help automate repetitive tasks, and mean having to learn fewer tools. Node npm scripts also ensure that everyone is using the same command with the same flags.

What does the caret mean in package json?

Caret (^) notation: It is used for automatically updating the minor updates along with patch updates. Example: The ^1.2. 4 will update all the future Minor and patch updates, for example, ^1.2. 4 will automatically change the dependency to 1. x.x if any update occurs.

What is the package JSON file for?

The package.json file is kind of a manifest for your project. It can do a lot of things, completely unrelated. It's a central repository of configuration for tools, for example. It's also where npm and yarn store the names and versions for all the installed packages. It's empty!

What is package package JSON in react?

Package.json = Metadata associated with project + All Dependencies with version + scripts In the react project you can see the package.json file in the react project structure, double click on the package. json file and see the code, Please see below the code of the package.json file,

What is a JSON file in Node JS?

The package.json file is the heart of Node.js system. It is the manifest file of any Node.js project and contains the metadata of the project. The package.json file is the essential part to understand, learn and work with the Node.js.

What are the different types of dependencies in package JSON?

Among all types of dependencies in package.json, dependencies and devDependencies are the most frequently used, and the concepts are straightforward. Meanwhile, optionalDependencies and bundledDependencies are rarely used. The interesting and troublesome one is peerDependencies.


1 Answers

I didn't find official documentation for npm package phantomChildren. But encountered some other explanation: https://rushjs.io/pages/advanced/phantom_deps/. It is about rast, but explains behavior of npm dependencies pretty well.

For example library A might import definitions from libraries B and C, but then B and C can both import from D, which creates a “diamond dependency” between these four packages.

A “phantom dependency” occurs when a project uses a package that is not defined in its package.json file.

Some live example:

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.

To summarize: if package uses dependencies of it's own dependencies, it can be treated as phantomChildren. Package doesn't have such dependencies directly but uses it from other places.

like image 138
Alex Vovchuk Avatar answered Jan 02 '23 23:01

Alex Vovchuk