[Front-end Notes] How to update project dependencies

The Node Package Manager (NPM) provides various features to help you install and maintain your project's dependencies.

Dependencies may become obsolete over time due to bug fixes, new features, and other updates. The more dependencies your project has, the harder it will be to keep up with these updates.

Sometimes, new software packages do not necessarily have a destructive impact on old projects, but may also bring good improvements or experience to the project's performance. Therefore, it is also important to regularly check the project's dependencies and update them.

1. Check the versions that the project depends on

npm outdated

This command can list the installed dependencies in the project, and will print out a table in the terminal describing the version information of the dependencies, as follows:
Insert image description here

  • Package: dependent package name
  • Current: currently installed version
  • Wanted: the desired version
  • Latest: the latest version of the dependency package

2. How to update dependent versions

npm update
// or
npm update <package>[@version]

Remember that with npm update it will never update to a major, version with breaking changes. It updates dependencies in package.json and package-lock.json. It will use the desired version.

The implication is that when npm update is used, the dependency will not be updated to the expected version viewed when npm outdated. So what if you want to update to the latest version you want?

3. Use npm-check-updates to update dependencies

// 1、安装依赖
npm install -g npm-check-updates
// 2、显示需要升级的依赖包
ncu
// 3、升级依赖
ncu --upgrade
// or
ncu -u

This method only updates dependencies in the package.json file and will select the latest version, even if it includes a breaking change. Using this method, npm install will not run automatically, so be sure to run it afterwards to update package-lock.json.

After , you can see that the dependent package version in package.json has been updated to the expected version when npm outdated. update successed! Wanted

Guess you like

Origin blog.csdn.net/qq_43398736/article/details/131393648