Node update a specific package

2019-03-08 06:43发布

问题:

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-sync GUI :(

├─┬ browser-sync@1.9.2
│ ├── browser-sync-client@1.0.2

回答1:

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

npm update browser-sync
  • Use npm outdated to see which modules have newer versions
  • Use npm update (without a package name) to update all modules
  • Include --save-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).

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

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

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

...or the latest and greatest by doing:

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

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

npm uninstall browser-sync --save-dev
npm install browser-sync --save-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. If you omit the --save-dev part, it's no different than running the update command above.