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