How do you reinstall an app's dependencies using npm?

后端 未结 10 2344
陌清茗
陌清茗 2020-12-07 07:22

Is there a simple way to reinstall all packages that my app depends on (i.e. they are in my apps node_modules folder)?

相关标签:
10条回答
  • 2020-12-07 07:43

    npm updated the CLI command for install and added the --force flag.

    npm install --force
    

    The --force (or -f) argument will force npm to fetch remote resources even if a local copy exists on disk.

    See npm install

    0 讨论(0)
  • 2020-12-07 07:45

    Most of the time I use the following command to achieve a complete reinstall of all the node modules (be sure you are in the project folder).

    rm -rf node_modules && npm install
    

    You can also run npm cache clean after removing the node_modules folder to be sure there aren't any cached dependencies.

    0 讨论(0)
  • 2020-12-07 07:47

    The right way is to execute npm update. It's a really powerful command, it updates the missing packages and also checks if a newer version of package already installed can be used.

    Read Intro to NPM to understand what you can do with npm.

    0 讨论(0)
  • 2020-12-07 07:54

    You can do this with one simple command:

    npm ci
    

    Documentation:

    npm ci
    Install a project with a clean slate

    0 讨论(0)
  • 2020-12-07 07:54

    You can use the reinstall module found in npm.

    After installing it, you can use the following command:

    reinstall
    

    The only difference with manually removing node_modules folder and making npm install is that this command automatically clear npm's cache. So, you can get three steps in one command.

    upd: npx reinstall is a way to run this command without globally installing package (only for npm5+)

    0 讨论(0)
  • 2020-12-07 07:57

    As of npm/cli v6.5.0

    npm clean-install
    

    Sources:

    https://github.com/npm/cli/releases/tag/v6.5.0 https://github.com/npm/cli/commit/fc1a8d185fc678cdf3784d9df9eef9094e0b2dec

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