11cb0ef41Sopenharmony_ci---
21cb0ef41Sopenharmony_cititle: npm-explain
31cb0ef41Sopenharmony_cisection: 1
41cb0ef41Sopenharmony_cidescription: Explain installed packages
51cb0ef41Sopenharmony_ci---
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci### Synopsis
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci```bash
101cb0ef41Sopenharmony_cinpm explain <package-spec>
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cialias: why
131cb0ef41Sopenharmony_ci```
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci### Description
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ciThis command will print the chain of dependencies causing a given package
181cb0ef41Sopenharmony_cito be installed in the current project.
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciIf one or more package specs are provided, then only packages matching
211cb0ef41Sopenharmony_cione of the specifiers will have their relationships explained.
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciThe package spec can also refer to a folder within `./node_modules`
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciFor example, running `npm explain glob` within npm's source tree will show:
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci```bash
281cb0ef41Sopenharmony_ciglob@7.1.6
291cb0ef41Sopenharmony_cinode_modules/glob
301cb0ef41Sopenharmony_ci  glob@"^7.1.4" from the root project
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciglob@7.1.1 dev
331cb0ef41Sopenharmony_cinode_modules/tacks/node_modules/glob
341cb0ef41Sopenharmony_ci  glob@"^7.0.5" from rimraf@2.6.2
351cb0ef41Sopenharmony_ci  node_modules/tacks/node_modules/rimraf
361cb0ef41Sopenharmony_ci    rimraf@"^2.6.2" from tacks@1.3.0
371cb0ef41Sopenharmony_ci    node_modules/tacks
381cb0ef41Sopenharmony_ci      dev tacks@"^1.3.0" from the root project
391cb0ef41Sopenharmony_ci```
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciTo explain just the package residing at a specific folder, pass that as the
421cb0ef41Sopenharmony_ciargument to the command.  This can be useful when trying to figure out
431cb0ef41Sopenharmony_ciexactly why a given dependency is being duplicated to satisfy conflicting
441cb0ef41Sopenharmony_civersion requirements within the project.
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci```bash
471cb0ef41Sopenharmony_ci$ npm explain node_modules/nyc/node_modules/find-up
481cb0ef41Sopenharmony_cifind-up@3.0.0 dev
491cb0ef41Sopenharmony_cinode_modules/nyc/node_modules/find-up
501cb0ef41Sopenharmony_ci  find-up@"^3.0.0" from nyc@14.1.1
511cb0ef41Sopenharmony_ci  node_modules/nyc
521cb0ef41Sopenharmony_ci    nyc@"^14.1.1" from tap@14.10.8
531cb0ef41Sopenharmony_ci    node_modules/tap
541cb0ef41Sopenharmony_ci      dev tap@"^14.10.8" from the root project
551cb0ef41Sopenharmony_ci```
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ci### Configuration
581cb0ef41Sopenharmony_ci#### `json`
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci* Default: false
611cb0ef41Sopenharmony_ci* Type: Boolean
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ciWhether or not to output JSON data, rather than the normal output.
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci* In `npm pkg set` it enables parsing set values with JSON.parse() before
661cb0ef41Sopenharmony_ci  saving them to your `package.json`.
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ciNot supported by all npm commands.
691cb0ef41Sopenharmony_ci
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci#### `workspace`
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci* Default:
751cb0ef41Sopenharmony_ci* Type: String (can be set multiple times)
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ciEnable running a command in the context of the configured workspaces of the
781cb0ef41Sopenharmony_cicurrent project while filtering by running only the workspaces defined by
791cb0ef41Sopenharmony_cithis configuration option.
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ciValid values for the `workspace` config are either:
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci* Workspace names
841cb0ef41Sopenharmony_ci* Path to a workspace directory
851cb0ef41Sopenharmony_ci* Path to a parent workspace directory (will result in selecting all
861cb0ef41Sopenharmony_ci  workspaces within that folder)
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ciWhen set for the `npm init` command, this may be set to the folder of a
891cb0ef41Sopenharmony_ciworkspace which does not yet exist, to create the folder and set it up as a
901cb0ef41Sopenharmony_cibrand new workspace within the project.
911cb0ef41Sopenharmony_ci
921cb0ef41Sopenharmony_ciThis value is not exported to the environment for child processes.
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci### See Also
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci* [package spec](/using-npm/package-spec)
971cb0ef41Sopenharmony_ci* [npm config](/commands/npm-config)
981cb0ef41Sopenharmony_ci* [npmrc](/configuring-npm/npmrc)
991cb0ef41Sopenharmony_ci* [npm folders](/configuring-npm/folders)
1001cb0ef41Sopenharmony_ci* [npm ls](/commands/npm-ls)
1011cb0ef41Sopenharmony_ci* [npm install](/commands/npm-install)
1021cb0ef41Sopenharmony_ci* [npm link](/commands/npm-link)
1031cb0ef41Sopenharmony_ci* [npm prune](/commands/npm-prune)
1041cb0ef41Sopenharmony_ci* [npm outdated](/commands/npm-outdated)
1051cb0ef41Sopenharmony_ci* [npm update](/commands/npm-update)
106