Have you ever encountered NPM and CNPM used together when there are strange problems? Have you ever encountered CNPM in alipay small program above the installation package is invalid? Are they really just switching a request source?

I believe that a lot of friend use CNPM purpose is very simple, that is to faster download things, he will change request source to https://registry.npm.taobao.org

So, we just

npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy the code

Then use CNPM instead of NPM, and once this is played, with the above mentioned problems, but may not be found for a time.

(In addition, there are also CNPM to execute. NPMRC, even using CNPM at this time will be very slow)

The cause of

I NPM install a thing, and then found that the previous problems, I suddenly panic, I just install, how can modify the previous things. So I looked at the problem carefully, and then couldn’t find it, so I asked the big guy.

why

LinGo replies

Because CNPM uses soft links by default, it will cause the NPM installation to update the previous CNPM package, and then the previous CNPM import will gg, so, a lot of things.

So we can see that the reason is CNPM itself, if we don’t use it, the problem is solved

So the easiest way is to use NPM install some < parameter > – registry=https://registry.npm.taobao.org

It’s perfect, but it’s a hassle

At this point, you can upgrade and use NRM

A better way

npm install -g nrm
nrm use cnpm
Copy the code

Then you can enjoy a quick download with NPM.

nrm

That’s not the end of the story — at this point, what if CNPM has already been used for the project?

Ways to improve

cnpm i --by=npm
Copy the code

NPM and CNPM do not collide, for example CNPM I –by= NPM react

CNPM using npminstall by default. If you don’t like symlink mode for node_modules, you can change the installer to original npm. But you will lose the fastest install speed.

CNPM portal

— 完 —