1 ---
2 title: npm-prune
3 section: 1
4 description: Remove extraneous packages
5 github_repo: npm/cli
6 github_branch: latest
7 github_path: docs/lib/content/commands/npm-prune.md
8 redirect_from:
9 - /cli-commands/npm-prune
10 - /cli-commands/prune
11 - /cli-documentation/cli-commands/npm-prune
12 - /cli-documentation/cli-commands/prune
13 - /cli-documentation/commands/npm-prune
14 - /cli-documentation/commands/prune
15 - /cli-documentation/npm-prune
16 - /cli-documentation/prune
17 - /cli-documentation/v11/cli-commands/npm-prune
18 - /cli-documentation/v11/cli-commands/prune
19 - /cli-documentation/v11/commands/npm-prune
20 - /cli-documentation/v11/commands/prune
21 - /cli-documentation/v11/npm-prune
22 - /cli-documentation/v11/prune
23 - /cli/cli-commands/npm-prune
24 - /cli/cli-commands/prune
25 - /cli/commands/npm-prune
26 - /cli/commands/prune
27 - /cli/npm-prune
28 - /cli/prune
29 - /cli/v11/cli-commands/npm-prune
30 - /cli/v11/cli-commands/prune
31 - /cli/v11/commands/prune
32 - /cli/v11/npm-prune
33 - /cli/v11/prune
34 - /commands/npm-prune
35 - /commands/prune
36 ---
37
38 ### Synopsis
39
40 ```bash
41 npm prune [[<@scope>/]<pkg>...]
42 ```
43
44 ### Description
45
46 This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.
47
48 Extraneous packages are those present in the `node_modules` folder that are not listed as any package's dependency list.
49
50 If the `--omit=dev` flag is specified or the `NODE_ENV` environment variable is set to `production`, this command will remove the packages specified in your `devDependencies`.
51
52 If the `--dry-run` flag is used then no changes will actually be made.
53
54 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.
55
56 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.
57
58 ### Configuration
59
60 #### `omit`
61
62 - Default: 'dev' if the `NODE_ENV` environment variable is set to 'production'; otherwise, empty.
63 - Type: "dev", "optional", or "peer" (can be set multiple times)
64
65 Dependency types to omit from the installation tree on disk.
66
67 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.
68
69 If a package type appears in both the `--include` and `--omit` lists, then it will be included.
70
71 If the resulting omit list includes `'dev'`, then the `NODE_ENV` environment variable will be set to `'production'` for all lifecycle scripts.
72
73 #### `include`
74
75 - Default:
76 - Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
77
78 Option that allows for defining which types of dependencies to install.
79
80 This is the inverse of `--omit=<type>`.
81
82 Dependency types specified in `--include` will not be omitted, regardless of the order in which omit/include are specified on the command-line.
83
84 #### `dry-run`
85
86 - Default: false
87 - Type: Boolean
88
89 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`.
90
91 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
92
93 #### `json`
94
95 - Default: false
96 - Type: Boolean
97
98 Whether or not to output JSON data, rather than the normal output.
99
100 - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`.
101
102 Not supported by all npm commands.
103
104 #### `foreground-scripts`
105
106 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
107 - Type: Boolean
108
109 Run all build scripts (ie, `preinstall`, `install`, and `postinstall`) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.
110
111 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
112
113 #### `ignore-scripts`
114
115 - Default: false
116 - Type: Boolean
117
118 If true, npm does not run scripts specified in package.json files.
119
120 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
121
122 #### `workspace`
123
124 - Default:
125 - Type: String (can be set multiple times)
126
127 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.
128
129 Valid values for the `workspace` config are either:
130
131 - Workspace names
132 - Path to a workspace directory
133 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
134
135 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.
136
137 This value is not exported to the environment for child processes.
138
139 #### `workspaces`
140
141 - Default: null
142 - Type: null or Boolean
143
144 Set to true to run the command in the context of **all** configured workspaces.
145
146 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
147
148 - Commands that operate on the `node_modules` tree (install, update, etc.) will link workspaces into the `node_modules` folder. - Commands that do other things (test, exec, publish, etc.) will operate on the root project, _unless_ one or more workspaces are specified in the `workspace` config.
149
150 This value is not exported to the environment for child processes.
151
152 #### `include-workspace-root`
153
154 - Default: false
155 - Type: Boolean
156
157 Include the workspace root when workspaces are enabled for a command.
158
159 When false, specifying individual workspaces via the `workspace` config, or all workspaces via the `workspaces` flag, will cause npm to operate only on the specified workspaces, and not on the root project.
160
161 This value is not exported to the environment for child processes.
162
163 #### `install-links`
164
165 - Default: false
166 - Type: Boolean
167
168 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
169
170 ### See Also
171
172 - [npm uninstall](/cli/v11/commands/npm-uninstall)
173 - [npm folders](/cli/v11/configuring-npm/folders)
174 - [npm ls](/cli/v11/commands/npm-ls)