npm command to uninstall or prune unused packages in Node.js

后端 未结 3 596
迷失自我
迷失自我 2020-12-04 04:46

Is there a way to simply uninstall all unused (undeclared) dependencies from a Node.js project (ones that are no longer defined in my package.json.) When I upda

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 05:35

    Note: Recent npm versions do this automatically when package-locks are enabled, so this is not necessary except for removing development packages with the --production flag.


    Run npm prune to remove modules not listed in package.json.

    From npm help prune:

    This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.

    Extraneous packages are packages that are not listed on the parent package's dependencies list.

    If the --production flag is specified, this command will remove the packages specified in your devDependencies.

提交回复
热议问题