Make `npm install --save` add a strict version to package.json

前端 未结 3 1484
走了就别回头了
走了就别回头了 2021-01-30 05:06

When you run npm install --save somepackage, it usually adds something like this into package.json:

\"dependencies\": {
    \"somepackage\": \"^2.1.         


        
相关标签:
3条回答
  • 2021-01-30 05:22

    To specify by default a exact version, you can change your npm config with save-exact:

    npm config set save-exact true
    

    You can also specify the prepend version with a tilde with save-prefix.

    And, no you can't force user to update to a minor or a patch version, NPM uses semver and it's the recommend way of publishing packages.

    0 讨论(0)
  • 2021-01-30 05:38

    Run:

    npm install --save --save-exact my-module@my-specific-version
    

    Adding an answer to make this advice easier to see.

    0 讨论(0)
  • 2021-01-30 05:42

    You can change the default behaviour by using the --save-exact option.

    // npm
    npm install --save --save-exact react
    
    // yarn
    yarn add --exact react
    

    I created a blog post about this if anyone is looking for this in the future.

    https://www.dalejefferson.com/blog/how-to-save-exact-npm-package-versions/

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