1---
2title: npm-explain
3section: 1
4description: Explain installed packages
5---
6
7### Synopsis
8
9```bash
10npm explain <package-spec>
11
12alias: why
13```
14
15### Description
16
17This command will print the chain of dependencies causing a given package
18to be installed in the current project.
19
20If one or more package specs are provided, then only packages matching
21one of the specifiers will have their relationships explained.
22
23The package spec can also refer to a folder within `./node_modules`
24
25For example, running `npm explain glob` within npm's source tree will show:
26
27```bash
28glob@7.1.6
29node_modules/glob
30  glob@"^7.1.4" from the root project
31
32glob@7.1.1 dev
33node_modules/tacks/node_modules/glob
34  glob@"^7.0.5" from rimraf@2.6.2
35  node_modules/tacks/node_modules/rimraf
36    rimraf@"^2.6.2" from tacks@1.3.0
37    node_modules/tacks
38      dev tacks@"^1.3.0" from the root project
39```
40
41To explain just the package residing at a specific folder, pass that as the
42argument to the command.  This can be useful when trying to figure out
43exactly why a given dependency is being duplicated to satisfy conflicting
44version requirements within the project.
45
46```bash
47$ npm explain node_modules/nyc/node_modules/find-up
48find-up@3.0.0 dev
49node_modules/nyc/node_modules/find-up
50  find-up@"^3.0.0" from nyc@14.1.1
51  node_modules/nyc
52    nyc@"^14.1.1" from tap@14.10.8
53    node_modules/tap
54      dev tap@"^14.10.8" from the root project
55```
56
57### Configuration
58#### `json`
59
60* Default: false
61* Type: Boolean
62
63Whether or not to output JSON data, rather than the normal output.
64
65* In `npm pkg set` it enables parsing set values with JSON.parse() before
66  saving them to your `package.json`.
67
68Not supported by all npm commands.
69
70
71
72#### `workspace`
73
74* Default:
75* Type: String (can be set multiple times)
76
77Enable running a command in the context of the configured workspaces of the
78current project while filtering by running only the workspaces defined by
79this configuration option.
80
81Valid values for the `workspace` config are either:
82
83* Workspace names
84* Path to a workspace directory
85* Path to a parent workspace directory (will result in selecting all
86  workspaces within that folder)
87
88When set for the `npm init` command, this may be set to the folder of a
89workspace which does not yet exist, to create the folder and set it up as a
90brand new workspace within the project.
91
92This value is not exported to the environment for child processes.
93
94### See Also
95
96* [package spec](/using-npm/package-spec)
97* [npm config](/commands/npm-config)
98* [npmrc](/configuring-npm/npmrc)
99* [npm folders](/configuring-npm/folders)
100* [npm ls](/commands/npm-ls)
101* [npm install](/commands/npm-install)
102* [npm link](/commands/npm-link)
103* [npm prune](/commands/npm-prune)
104* [npm outdated](/commands/npm-outdated)
105* [npm update](/commands/npm-update)
106