Node update a specific package

后端 未结 3 958
清酒与你
清酒与你 2020-12-12 11:05

I want to update my Browser-sync without updating all my node packages. How can I achieve this? My current version of Browser-sync does not have the Browser

相关标签:
3条回答
  • 2020-12-12 11:11

    Most of the time you can just npm update (or yarn upgrade) a module to get the latest non breaking changes (respecting the semver specified in your package.json) (<-- read that last part again).

    npm update browser-sync
    -------
    yarn upgrade browser-sync
    
    • Use npm|yarn outdated to see which modules have newer versions
    • Use npm update|yarn upgrade (without a package name) to update all modules
    • Include --save-dev|--dev if you want to save the newer version numbers to your package.json. (NOTE: as of npm v5.0 this is only necessary for devDependencies).

    Major version upgrades:

    In your case, it looks like you want the next major version (v2.x.x), which is likely to have breaking changes and you will need to update your app to accommodate those changes. You can install/save the latest 2.x.x by doing:

    npm install browser-sync@2 --save-dev
    -------
    yarn add browser-sync@2 --dev
    

    ...or the latest 2.1.x by doing:

    npm install browser-sync@2.1 --save-dev
    -------
    yarn add browser-sync@2.1 --dev
    

    ...or the latest and greatest by doing:

    npm install browser-sync@latest --save-dev
    -------
    yarn add browser-sync@latest --dev
    

    Note: the last one is no different than doing this:

    npm uninstall browser-sync --save-dev
    npm install browser-sync --save-dev
    -------
    yarn remove browser-sync --dev
    yarn add browser-sync --dev
    

    The --save-dev part is important. This will uninstall it, remove the value from your package.json, and then reinstall the latest version and save the new value to your package.json.

    0 讨论(0)
  • 2020-12-12 11:20

    Use npm outdated to see Current and Latest version of all packages.


    Then npm i packageName@versionNumber to install specific version : example npm i browser-sync@2.1.0.

    Or npm i packageName@latest to install latest version : example npm i browser-sync@latest.

    0 讨论(0)
  • 2020-12-12 11:28

    Always you can do it manually. Those are the steps:

    • Go to the NPM package page, and search for the GitHub link.
    • Now download the latest version using GitHub download link, or by clonning. git clone github_url
    • Copy the package to your node_modules folder for e.g. node_modules/browser-sync

    Now it should work for you. To be sure it will not break in the future when you do npm i, continue the upcoming two steps:

    • Check the version of the new package by reading the package.json file in it's folder.
    • Open your project package.json and set the same version for where it's appear in the dependencies part of your package.json

    While it's not recommened to do it manually. Sometimes it's good to understand how things are working under the hood, to be able to fix things. I found myself doing it from time to time.

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