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