NPM updates dependency packages in three ways

1. Use basic commands

  • View the global installation package
npm list -g --depth 0
Copy the code
  • Viewing the Installation PackagepackageNameLatest version information
npm view | info packageName version
Copy the code
  • View the remote installation packagepackageNameRelease information for all releases of
npm view | info packageName versions
Copy the code
  • Check for outdated installation packages
npm outdated [packageName]
Copy the code

Version Information

Package Displays the Package name. If –long / -l is used, the package belongs to Dependencies or devDependency

Current Current dependency package installation version

Wanted The latest version number that can be updated according to package.json package version prefix rules

Latest package version number (by default, this is the Latest, depending on the developer’s package management regime)

Location is the Location of the dependency package in the dependency tree

Package font color meaning

  1. Red package.json dependencies with updatable package version prefix rules

  2. Yellow package.json dependencies with package version prefix rules that cannot be updated

Dependent version cognition

The dependency packages of the project are generally saved in package.json file, and the corresponding version number is in the form of mojor.minor.patch

Major means a major API change that is not compatible (major)

Minor represents backward compatible functional changes (minor)

Patch stands for backward compatible bug fixes (patched)

Meaning of the prefix of the version number of the dependent package

  • * Matches the latest major version dependency package

  • ^ Matches the latest minor version of the dependency package, eg: 1.1.0 can be updated to match all 1.x.x packages, not to match 2.x.x

  • ~ Matches the latest patch version dependency packages, eg: 1.1.0 can update all packages that match 1.1.x, but not 1.2.x

  • No prefix indicates a fixed version number, and the version will not be updated to match any other version. [Need to manually change package version of package.json]

Second, the NPM update

  • Update specified dependency packagesmajorBit updates are sometimes required inpackage.jsonManually change the corresponding version number of the dependency package in the update.
    • -S dependenciesDependency installation (–save) in production environment, default installation
    • -D devDependenciesDependency installation in development environment (–save-dev)
npm update packageName (-D | -S)
Copy the code

Differences between NPM I and NPM Update

The following description:

  • packageIndicates that package.json depends on a version management file
  • lockPackage-lock. json locks dependent version files
  1. lockFile exists
  • NPM I will be installed according to the corresponding package version of Lock and will not be automatically upgraded

    • Manual changespackageCorresponding package,lockWill be in accordance with thepackagePrefix version specification updated to the latest version,packageThe version is manual
  • NPM update is installed to the latest version according to the package version prefix upgrade specification

    • packageAccording to the latest version of the prefix specification andlockThe same will not change, the different will change.
    • lockThe corresponding package version number in
  1. lockFile does not exist
  • NPM I is installed to the latest version of package.json according to the package version prefix upgrade specification

    • package.jsonStill the prefix specification version number
    • package-lock.jsonUpgrade to the latest version according to the version prefix specification
  • NPM UPDATE is similar to NPM I

    • But ignoredevDependenciesThe corresponding package under update installation
    • added-DBefore the update is installeddependenciesUnder the premise of the update installationdevDependenciesBelow the corresponding dependency packages

Third, NPM – check – updates

  • The global installation depends on nPm-check-update
npm install npm-check-update -g
Copy the code
  • Check updatable modules
Ncu or NPM - check - updateCopy the code
  • Update updatable modules [It is not recommended to update all updatable dependencies at once] (updates include updates to the major bit)
ncu -u [packageName]
Copy the code

Fourth, NPM – check

  • The global installation depends on NPm-check
npm install npm-check -g
Copy the code
  • View information about updatable packages
npm-check
Copy the code
  • Select and update the corresponding dependency package
npm-check -u
Copy the code

Five, the difference between the three methods

The difference between:

npm update

  1. npm update [packageName]Will update synchronouslypackage-lock.jsonThe version of the corresponding package in the file, no need to reinstall the NPM package

NPM – check – updates and NPM – check

  1. The two are basically the same, but there are some differences in some forms of interaction during the update process

  2. Update the updatable installation package in package.json file, but not the version of the corresponding package in the corresponding package-lock.json file

  3. Dependencies need to be reinstalled using the following command:

rm -rf package-lock.json && npm i
Copy the code

Refer to the link

  • How do I update dependencies in package.json

  • Install, update, and delete NPM dependencies

  • [NPM module management advanced – NPm-check + CNPM build package update environment]