main
@reggi/path-to-regexp
dependabot/npm_and_yarn/main/copy-to-clipboard-4.0.2
dependabot/npm_and_yarn/main/eslint-10.4.0
dependabot/npm_and_yarn/main/npmcli/eslint-config-7.0.0
dependabot/npm_and_yarn/main/proc-log-7.0.0
dependabot/npm_and_yarn/npm_and_yarn-826852524d
dependabot/npm_and_yarn/npm_and_yarn-ab9a7f4bc2
deprecate-totp-2fa
dhei/classic-tokens
gat-bypass-2fa-docs
jpg619/fix-accessibility-content-flow
jpg619/version-bump-tar-2
kartykp/gat-bypass-2fa-docs
kartykp/upgrade-path-to-regex
main
maitxn/version-bump-tar
patch-1
reggi/cache-based-on-version
reggi/dev-engines
reggi/fix-transform-prettier
reggi/overrides
update-search-sensitivity
| 1 | --- |
| 2 | title: npm-explain |
| 3 | section: 1 |
| 4 | description: Explain installed packages |
| 5 | github_repo: npm/cli |
| 6 | github_branch: latest |
| 7 | github_path: docs/lib/content/commands/npm-explain.md |
| 8 | redirect_from: |
| 9 | - /cli-commands/explain |
| 10 | - /cli-commands/npm-explain |
| 11 | - /cli-documentation/cli-commands/explain |
| 12 | - /cli-documentation/cli-commands/npm-explain |
| 13 | - /cli-documentation/commands/explain |
| 14 | - /cli-documentation/commands/npm-explain |
| 15 | - /cli-documentation/explain |
| 16 | - /cli-documentation/npm-explain |
| 17 | - /cli-documentation/v11/cli-commands/explain |
| 18 | - /cli-documentation/v11/cli-commands/npm-explain |
| 19 | - /cli-documentation/v11/commands/explain |
| 20 | - /cli-documentation/v11/commands/npm-explain |
| 21 | - /cli-documentation/v11/explain |
| 22 | - /cli-documentation/v11/npm-explain |
| 23 | - /cli/cli-commands/explain |
| 24 | - /cli/cli-commands/npm-explain |
| 25 | - /cli/commands/explain |
| 26 | - /cli/commands/npm-explain |
| 27 | - /cli/explain |
| 28 | - /cli/npm-explain |
| 29 | - /cli/v11/cli-commands/explain |
| 30 | - /cli/v11/cli-commands/npm-explain |
| 31 | - /cli/v11/commands/explain |
| 32 | - /cli/v11/explain |
| 33 | - /cli/v11/npm-explain |
| 34 | - /commands/explain |
| 35 | - /commands/npm-explain |
| 36 | --- |
| 37 | |
| 38 | ### Synopsis |
| 39 | |
| 40 | ```bash |
| 41 | npm explain <package-spec> |
| 42 | |
| 43 | alias: why |
| 44 | ``` |
| 45 | |
| 46 | ### Description |
| 47 | |
| 48 | This command will print the chain of dependencies causing a given package to be installed in the current project. |
| 49 | |
| 50 | If one or more package specs are provided, then only packages matching one of the specifiers will have their relationships explained. |
| 51 | |
| 52 | The package spec can also refer to a folder within `./node_modules` |
| 53 | |
| 54 | For example, running `npm explain glob` within npm's source tree will show: |
| 55 | |
| 56 | ```bash |
| 57 | glob@7.1.6 |
| 58 | node_modules/glob |
| 59 | glob@"^7.1.4" from the root project |
| 60 | |
| 61 | glob@7.1.1 dev |
| 62 | node_modules/tacks/node_modules/glob |
| 63 | glob@"^7.0.5" from rimraf@2.6.2 |
| 64 | node_modules/tacks/node_modules/rimraf |
| 65 | rimraf@"^2.6.2" from tacks@1.3.0 |
| 66 | node_modules/tacks |
| 67 | dev tacks@"^1.3.0" from the root project |
| 68 | ``` |
| 69 | |
| 70 | 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. |
| 71 | |
| 72 | ```bash |
| 73 | $ npm explain node_modules/nyc/node_modules/find-up |
| 74 | find-up@3.0.0 dev |
| 75 | node_modules/nyc/node_modules/find-up |
| 76 | find-up@"^3.0.0" from nyc@14.1.1 |
| 77 | node_modules/nyc |
| 78 | nyc@"^14.1.1" from tap@14.10.8 |
| 79 | node_modules/tap |
| 80 | dev tap@"^14.10.8" from the root project |
| 81 | ``` |
| 82 | |
| 83 | ### Configuration |
| 84 | |
| 85 | #### `json` |
| 86 | |
| 87 | - Default: false |
| 88 | - Type: Boolean |
| 89 | |
| 90 | Whether or not to output JSON data, rather than the normal output. |
| 91 | |
| 92 | - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`. |
| 93 | |
| 94 | Not supported by all npm commands. |
| 95 | |
| 96 | #### `workspace` |
| 97 | |
| 98 | - Default: |
| 99 | - Type: String (can be set multiple times) |
| 100 | |
| 101 | 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. |
| 102 | |
| 103 | Valid values for the `workspace` config are either: |
| 104 | |
| 105 | - Workspace names |
| 106 | - Path to a workspace directory |
| 107 | - Path to a parent workspace directory (will result in selecting all workspaces within that folder) |
| 108 | |
| 109 | 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. |
| 110 | |
| 111 | This value is not exported to the environment for child processes. |
| 112 | |
| 113 | ### See Also |
| 114 | |
| 115 | - [package spec](/cli/v11/using-npm/package-spec) |
| 116 | - [npm config](/cli/v11/commands/npm-config) |
| 117 | - [npmrc](/cli/v11/configuring-npm/npmrc) |
| 118 | - [npm folders](/cli/v11/configuring-npm/folders) |
| 119 | - [npm ls](/cli/v11/commands/npm-ls) |
| 120 | - [npm install](/cli/v11/commands/npm-install) |
| 121 | - [npm link](/cli/v11/commands/npm-link) |
| 122 | - [npm prune](/cli/v11/commands/npm-prune) |
| 123 | - [npm outdated](/cli/v11/commands/npm-outdated) |
| 124 | - [npm update](/cli/v11/commands/npm-update) |