1 ---
2 title: npm-prune
3 section: 1
4 description: Remove extraneous packages
5 github_repo: npm/cli
6 github_branch: release/v10
7 github_path: docs/lib/content/commands/npm-prune.md
8 redirect_from:
9 - /cli-documentation/v10/cli-commands/npm-prune
10 - /cli-documentation/v10/cli-commands/prune
11 - /cli-documentation/v10/commands/npm-prune
12 - /cli-documentation/v10/commands/prune
13 - /cli-documentation/v10/npm-prune
14 - /cli-documentation/v10/prune
15 - /cli/v10/cli-commands/npm-prune
16 - /cli/v10/cli-commands/prune
17 - /cli/v10/commands/prune
18 - /cli/v10/npm-prune
19 - /cli/v10/prune
20 ---
21
22 ### Synopsis
23
24 ```bash
25 npm prune [[<@scope>/]<pkg>...]
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 `--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`.
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 #### `include`
58
59 - Default:
60 - Type: "prod", "dev", "optional", or "peer" (can be set multiple times)
61
62 Option that allows for defining which types of dependencies to install.
63
64 This is the inverse of `--omit=<type>`.
65
66 Dependency types specified in `--include` will not be omitted, regardless of the order in which omit/include are specified on the command-line.
67
68 #### `dry-run`
69
70 - Default: false
71 - Type: Boolean
72
73 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`.
74
75 Note: This is NOT honored by other network related commands, eg `dist-tags`, `owner`, etc.
76
77 #### `json`
78
79 - Default: false
80 - Type: Boolean
81
82 Whether or not to output JSON data, rather than the normal output.
83
84 - In `npm pkg set` it enables parsing set values with JSON.parse() before saving them to your `package.json`.
85
86 Not supported by all npm commands.
87
88 #### `foreground-scripts`
89
90 - Default: `false` unless when using `npm pack` or `npm publish` where it defaults to `true`
91 - Type: Boolean
92
93 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.
94
95 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
96
97 #### `ignore-scripts`
98
99 - Default: false
100 - Type: Boolean
101
102 If true, npm does not run scripts specified in package.json files.
103
104 Note that commands explicitly intended to run a particular script, such as `npm start`, `npm stop`, `npm restart`, `npm test`, and `npm run-script` will still run their intended script if `ignore-scripts` is set, but they will _not_ run any pre- or post-scripts.
105
106 #### `workspace`
107
108 - Default:
109 - Type: String (can be set multiple times)
110
111 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.
112
113 Valid values for the `workspace` config are either:
114
115 - Workspace names
116 - Path to a workspace directory
117 - Path to a parent workspace directory (will result in selecting all workspaces within that folder)
118
119 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.
120
121 This value is not exported to the environment for child processes.
122
123 #### `workspaces`
124
125 - Default: null
126 - Type: null or Boolean
127
128 Set to true to run the command in the context of **all** configured workspaces.
129
130 Explicitly setting this to false will cause commands like `install` to ignore workspaces altogether. When not set explicitly:
131
132 - 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.
133
134 This value is not exported to the environment for child processes.
135
136 #### `include-workspace-root`
137
138 - Default: false
139 - Type: Boolean
140
141 Include the workspace root when workspaces are enabled for a command.
142
143 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.
144
145 This value is not exported to the environment for child processes.
146
147 #### `install-links`
148
149 - Default: false
150 - Type: Boolean
151
152 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.
153
154 ### See Also
155
156 - [npm uninstall](/cli/v10/commands/npm-uninstall)
157 - [npm folders](/cli/v10/configuring-npm/folders)
158 - [npm ls](/cli/v10/commands/npm-ls)