“This is the second day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

preface

The project installs dependencies A, and dependencies A installs dependencies B.

Rely on B quit (with the new version | | pail), after the new installation project equipment installation, found that rely on A wrong.

Moreover, if we use automated deployment, each deployment is equivalent to reinstalling dependencies

To circumvent the above problem, we need to anchor dependencies

Some prep points

  1. In the package. The json version
  2. NPM publishes dependencies
  3. NPM views dependency information
  4. Changing the dependent source

In the package. The json version

Different expressions of dependent package information correspond to different packages. Choose a proper expression based on your own requirements. The default package is the first one below

Package. json {"dependencies": {"lan-test-package1": "^1.0.0", "lan-test-package2": "~1.0.0", "lan-test-package3": "1.0.0"}},Copy the code

“LAN – test – package1” : “^ 1.0.0”

Install the latest lan-test-package1 1.x.x package

“lan-test-package2”: “! 1.0.0”

Install the latest lan-test-package2 1.0.x package

“LAN – test – package3” : “1.0.0”

Install the lan-test-package3 1.0.0 package

NPM publishes dependency processes

  1. You can publish your own dependencies as needed
  2. Understanding the packet sending process can explain some of the dependency errors

Have an NPM account

www.npmjs.com/

Visit the NPM website to register

Local Construction Projects

Local scaffolding projects can be built using existing scaffolding or initialized using NPM init

Log in to the local account and publish the package

npm adduser
npm login
Copy the code

These two commands are literal. Generally we do not use NPM to manage their own dependencies need to add users. We are asked to enter our account name, password and email address, which is usually used to notify dependent updates and other information

npm publish
Copy the code

This is the issued command, executed at the root of the project. Will be executed according to our package.json file.

It should be noted that every time we update the package, we need to change the version number. If the version number is the same as before, the release will fail. After the successful release, an email will be sent to our previous verification email to inform us.

NPM Views dependency information

Dependency details

npm info vue
Copy the code

npm info vue@next
Copy the code

The previous two view commands view the version information of vue and vue@next respectively

List of dependent versions

npm view element-ui versions
Copy the code

npm view element-plus versions
Copy the code

The above two commands view the list of version numbers for Element-UI and Element-Plus, respectively.

Rely on the latest version

npm view ant-design-vue version
Copy the code

1.7.8

npm view ant-design-vue@next version
Copy the code

2.2.7

npm & cnpm

Viewing dependent Sources

npm config get registry
Copy the code

registry.npmjs.org/

cnpm config get registry
Copy the code

registry.npm.taobao.org/

Changing the dependent source

npm config set registry https://registry.npm.taobao.org/
Copy the code

This changes the dependency source of NPM to the source of Taobao mirror, but this usage is not recommended. You are advised to use CNPM to install dependencies if you want to use a domestic image. NPM still maintains its own official source, which is a prerequisite for logging in to NPM

The thesis comes late, fixed dependence

Fixed version in package.json

"Module1" : "1.0.0"Copy the code

We can guarantee that the installed dependency is of the version we specify, but we cannot save the version of the dependency

npm — package-lock.json

npm install
Copy the code

Using NPM to install dependencies, the root directory generates a pageage-lock.json file containing the project version lock information

yarn — yarn.lock

yarn install
Copy the code

After a project uses YARN to install dependencies, a yarn.lock file is generated in the root directory, which contains information about the version lock of the project

summary

  1. To publish NPM, you need to use NPM’s own source. However, NPM’s source installation is not fast enough. So I think that’s why a lot of people use YARN to install dependencies

  2. CNPM I will install package-lock.json according to package.json. If CNPM has package-lock.json, then I don’t need yarn

  3. The final form of the project is: the project’s package.json relies on the fixed + lock scheme in 1.0.0 form

  4. The best way to understand this problem is to create two dependencies of your own

  5. Oh, oh, and the bucket thing. This is a fixed version of the problem can not be solved, can only wait for students to install a new project after the report of the problem, consider updating the dependency or change to a new use