How to update each dependency in package.json to the latest version?

前端 未结 30 3321
清歌不尽
清歌不尽 2020-11-22 08:01

I copied package.json from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don\'t mind

30条回答
  •  不知归路
    2020-11-22 08:11

    To update one dependency to its lastest version without having to manually open the package.json and change it, you can run

    npm install {package-name}@* {save flags?}
    

    i.e.

    npm install express@* --save
    

    For reference, npm-install


    Update: Recent versions may need latest flag instead, i.e. npm install express@latest


    As noted by user Vespakoen on a rejected edit, it's also possible to update multiple packages at once this way:

    npm install --save package-nave@* other-package@* whatever-thing@*
    

    He also apports a one-liner for the shell based on npm outdated. See the edit for code and explanation.


    PS: I also hate having to manually edit package.json for things like that ;)

提交回复
热议问题