1 ---
2 title: npm-prune
3 section: 1
4 description: Remove extraneous packages
5 github_repo: npm/cli
6 github_branch: release/v7
7 github_path: docs/content/commands/npm-prune.md
8 redirect_from:
9 - /cli-documentation/v7/cli-commands/npm-prune
10 - /cli-documentation/v7/cli-commands/prune
11 - /cli-documentation/v7/commands/npm-prune
12 - /cli-documentation/v7/commands/prune
13 - /cli-documentation/v7/npm-prune
14 - /cli-documentation/v7/prune
15 - /cli/v7/cli-commands/npm-prune
16 - /cli/v7/cli-commands/prune
17 - /cli/v7/commands/prune
18 - /cli/v7/npm-prune
19 - /cli/v7/prune
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm prune [[<@scope>/]<pkg>...] [--production] [--dry-run] [--json]
26 ```
27
28 ### Description
29
30 This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.
31
32 Extraneous packages are those present in the `node_modules` folder that are not listed as any package's dependency list.
33
34 If the `--production` flag is specified or the `NODE_ENV` environment variable is set to `production`, this command will remove the packages specified in your `devDependencies`. Setting `--no-production` will negate `NODE_ENV` being set to `production`.
35
36 If the `--dry-run` flag is used then no changes will actually be made.
37
38 If the `--json` flag is used, then the changes `npm prune` made (or would have made with `--dry-run`) are printed as a JSON object.
39
40 In normal operation, extraneous modules are pruned automatically, so you'll only need this command with the `--production` flag. However, in the real world, operation is not always "normal". When crashes or mistakes happen, this command can help clean up any resulting garbage.
41
42 ### Configuration
43
44 #### `omit`
45
46 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production', otherwise empty.
47 - Type: "dev", "optional", or "peer" (can be set multiple times)
48
49 Dependency types to omit from the installation tree on disk.
50
51 Note that these dependencies _are_ still resolved and added to the `package-lock.json` or `npm-shrinkwrap.json` file. They are just not physically installed on disk.
52
53 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
54
55 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
56
57 #### `dry-run`
58
59 - Default: false
60 - Type: Boolean
61
62 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, `install`, `update`, `dedupe`, `uninstall`, as well as `pack` and `publish`.
63
64 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
65
66 #### `json`
67
68 - Default: false
69 - Type: Boolean
70
71 Whether or not to output JSON data, rather than the normal output.
72
73 - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`.
74
75 Not supported by all npm commands.
76
77 #### `workspace`
78
79 - Default:
80 - Type: String (can be set multiple times)
81
82 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.
83
84 Valid values for the `workspace` config are either:
85
86 - Workspace names
87 - Path to a workspace directory
88 - Path to a parent workspace directory (will result to selecting all of the nested workspaces)
89
90 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.
91
92 This value is not exported to the environment for child processes.
93
94 #### `workspaces`
95
96 - Default: false
97 - Type: Boolean
98
99 Enable running a command in the context of **all** the configured workspaces.
100
101 This value is not exported to the environment for child processes.
102
103 ### See Also
104
105 - [npm uninstall](/cli/v7/commands/npm-uninstall)
106 - [npm folders](/cli/v7/configuring-npm/folders)
107 - [npm ls](/cli/v7/commands/npm-ls)