How to clean node_modules folder of packages that are not in package.json?

后端 未结 13 1206
别那么骄傲
别那么骄傲 2020-12-02 03:58

Assume I install project packages with npm install that looks into package.json for modules to be installed. After a while I see that I don\'t need

相关标签:
13条回答
  • 2020-12-02 04:13

    simple just run

    rm -r node_modules
    

    in fact, you can delete any folder with this.

    like rm -r AnyFolderWhichIsNotDeletableFromShiftDeleteOrDelete.

    just open the gitbash move to root of the folder and run this command

    Hope this will help.

    0 讨论(0)
  • 2020-12-02 04:15

    Use following command instead of npm install

    npm ci
    
    0 讨论(0)
  • 2020-12-02 04:17

    First globally install rimraf

    npm install rimraf -g
    

    go to the path using cmd where your node_modules folder and apply below command

    rimraf node_modules
    
    0 讨论(0)
  • 2020-12-02 04:19

    I think you're looking for npm prune

    npm prune [<name> [<name ...]]

    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.

    See the docs: https://docs.npmjs.com/cli/prune

    0 讨论(0)
  • 2020-12-02 04:22

    For Windows User, alternative solution to remove such folder listed here: http://ask.osify.com/qa/567

    Among them, a free tool: Long Path Fixer is good to try: http://corz.org/windows/software/accessories/Long-Path-Fixer-for-Windows.php

    0 讨论(0)
  • 2020-12-02 04:25

    from version 6.5.0 npm supports the command clean-install to hard refresh all the packages

    0 讨论(0)
提交回复
热议问题