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