1. npm uses Taobao image
1. Configuration commands-the first command is the old version, the second one is the new version
npm config set registry https://registry.npm.taobao.org
npm config set registry https://registry.npmmirror.com/
2. Verify command
npm config get registry
The returned result is https://registry.npm.taobao.org, indicating that the Taobao mirror configuration is successful
3. Install using cnpm
Explanation: Because the npm installation plug-in is downloaded from a foreign server, it is greatly affected by the network, and abnormalities may occur, so the Taobao team we are happy to share did this. ! From the official website: "This is a complete npmjs.org mirror, you can use this instead of the official version (read-only), the synchronization frequency is currently every 10 minutes to ensure that it is as close as possible to the official service." ;
-g: Install globally.
npm install -g cnpm --registry=https://registry.npm.taobao.org
// 解决安装卡顿或无法安装
// 注册模块
npm set registry https://registry.npm.taobao.org
// node-gyp 编译依赖 node 源码镜像
npm set disturl https://npm.taobao.org/dist
// 清空缓存
npm cache clean --force
// 安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
After installation, it is best to check its version number cnpm -v or close the command prompt and reopen it. Errors may occur if you use it directly after installation
4. Use cnpm
The usage of cnpm is exactly the same as npm, except that npm is changed to cnpm when executing the command (the following operations will replace npm with cnpm).
2. Switch npm back to the official source
Delete the address to restore the default source
npm config delete registry
Or modify it directly to the original source
npm config set registry https://registry.npmjs.org/