The role of package-lock.json, if there is no solution in the project

Package-lock.json function: lock the version of the library used, if you install it next time, you will still use these versions of the library

When the developer installs the dependency according to package.json, the dependency version number declared in the file is not specific, but is downloaded to the new compatibility (download the latest version of the main version).
package-lock.json is npm installgenerated when a document, for each npm package record in the current state of the actual installation and version number of specific sources.
When other developers in the project or a new environment, or a new download source, reinstall the dependencies and include this file in the directory, the source and version number of the dependencies during installation will be locked to ensure that the dependencies installed by each developer are all it's the same.

In our work, the scene we often encounter is the code that can run on the colleague's machine. It can't be run in my new installation. It may be that some libraries are not compatible with the current scene after they are updated. The specific reasons are as follows:

  1. Conflict with other libraries
  2. Call api change
  3. Incompatible with the current development environment

The reason is that the version of the library written in package.json is often written like ~1.0, which means that as long as the major version is the same, the later minor version will use the latest, unless it is written like 1.0, only a version is specified

Solution when there is no package-lock.json in the project:

  1. Perform the installation once npm install, it will be automatically generated
  2. If you use npm, your colleagues must also use npm. If the other party uses yarn (yarn corresponds to yarn.lock), it will not work. In this case, you can only write the version of the library that is prone to problems with package.json.

Guess you like

Origin blog.csdn.net/weixin_40599109/article/details/108468314