2019-11-05 14:55:08 -05:00
|
|
|
---
|
|
|
|
title: npm-prune
|
2020-11-01 07:54:36 +01:00
|
|
|
section: 1
|
2019-11-05 14:55:08 -05:00
|
|
|
description: Remove extraneous packages
|
|
|
|
---
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2019-11-05 14:55:08 -05:00
|
|
|
### Synopsis
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2019-11-05 14:55:08 -05:00
|
|
|
```bash
|
|
|
|
npm prune [[<@scope>/]<pkg>...] [--production] [--dry-run] [--json]
|
|
|
|
```
|
|
|
|
|
|
|
|
### Description
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2020-12-11 18:54:56 -05:00
|
|
|
This command removes "extraneous" packages. If a package name is provided,
|
|
|
|
then only packages matching one of the supplied names are removed.
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2020-12-11 18:54:56 -05:00
|
|
|
Extraneous packages are those present in the `node_modules` folder that are
|
|
|
|
not listed as any package's dependency list.
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2015-06-12 04:04:17 -04:00
|
|
|
If the `--production` flag is specified or the `NODE_ENV` environment
|
|
|
|
variable is set to `production`, this command will remove the packages
|
2020-12-11 18:54:56 -05:00
|
|
|
specified in your `devDependencies`. Setting `--no-production` will negate
|
|
|
|
`NODE_ENV` being set to `production`.
|
2013-10-24 09:21:59 -07:00
|
|
|
|
2018-04-20 18:26:37 -07:00
|
|
|
If the `--dry-run` flag is used then no changes will actually be made.
|
|
|
|
|
2020-12-11 18:54:56 -05:00
|
|
|
If the `--json` flag is used, then the changes `npm prune` made (or would
|
2018-04-20 18:26:37 -07:00
|
|
|
have made with `--dry-run`) are printed as a JSON object.
|
|
|
|
|
2020-12-11 18:54:56 -05:00
|
|
|
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.
|
2018-04-20 18:26:37 -07:00
|
|
|
|
2019-11-05 14:55:08 -05:00
|
|
|
### See Also
|
2011-11-21 09:48:45 -08:00
|
|
|
|
2020-11-01 07:54:36 +01:00
|
|
|
* [npm uninstall](/commands/npm-uninstall)
|
2019-11-05 14:55:08 -05:00
|
|
|
* [npm folders](/configuring-npm/folders)
|
2020-11-01 07:54:36 +01:00
|
|
|
* [npm ls](/commands/npm-ls)
|