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