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