Want to use the shortest time to share a most simple, but not familiar knowledge. Without further ado, let’s begin…
“^”, “~”, “” in package.json
If you look carefully at your package.json file, you’ll notice that some dependencies are preceded by ^, some by ~, and some by no symbol at all
"devDependencies": {
"@alifd/next": "^ 1.22.11"."@babel/plugin-proposal-decorators": "~ 7.13.5"."axios": "^ 0.21.1"."classnames": "~ 2.2.6." "."moment": "2.29.1",}Copy the code
Note The rules for version numbers are as follows: [Major, minor, patch] : Major version, minor version, and patch version
-
^ Indicates that the major version will not change. Minor and patched versions will install the latest version. Here’s an example:
“@ alifd/next” : “^ 1.22.11”, version including > and < = 1.22.11 2.0.0
There is a catch. If the larger version is 0, the “^” and “~” will behave the same, because the larger version is 0, indicating that the program is in development phase, and even a small version number change may cause incompatibility.
“Axios “: “^0.21.1”, version includes >=0.21.1 and < 0.22.0
-
~ indicates that the major version and minor version do not change, and the latest patch version will be installed. Here’s an example:
“@babel/plugin-proposal-decorators”: “~7.13.5”, versions include >=7.13.5 and < 7.14.0
“Classnames “: “~2.2.6”, versions include >=2.2.6 and < 2.3.0
-
Specified version, that is, no ^, ~. Here’s an example:
“Moment “: “2.29.1” will only install version 2.29.1
What do package-lock.json and yarn.lock do
In fact, the name can guess the general function, is to lock the installed version. As we know from the above knowledge, the “^” and “~” before the version number may cause the source code of the dependency package installed at different time periods to be different, which may cause unknown errors in our program. To avoid this situation, whether you install yarn or NPM, Will give us a locked version of the file (package-lock.json and yarn.lock)
So don’t omit package-lock.json or yarn.lock when submitting code to the code base