前言
npm 淘宝镜像 和 cnpm 二者选其一即可,没有必要两个都添加
一、淘宝镜像
1. 打开命令行工具并执行以下命令
使用快捷键 win + R,并输入 cmd,回车输入以下命令,二者选其一即可,也可以两个都添加
npm
npm config set registry https://registry.npmmirror.com
2. 以管理员身份运行 Windows PowerShell 程序,并开启以下权限
可以在 windows 搜索框搜索,可快速查找到此程序
以管理员身份运行此程序后输入以下指令
set-ExecutionPolicy RemoteSigned
遇到选项时,输入 y 回车即可
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如 https:/go.microsoft.com/fwlink/?LinkID=135170
中的 about_Execution_Policies 帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”):y
3. 通过以下方式检查是否安装成功
npm
npm config get registry
成功结果
http://registry.npmmirror.com/
二、cnpm
1. 安装
cnpm
// 安装 cnpm 并添加淘宝镜像
npm install -g cnpm --registry=https://registry.npmmirror.com
2. 检查是否安装成功
cnpm
cnpm -v
成功结果
cnpm@9.0.1 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js)
npm@8.19.3 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\index.js)
node@14.16.0 (C:\Program Files\nodejs\node.exe)
npminstall@7.4.2 (C:\Users\DELL\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Users\DELL\AppData\Roaming\npm
win32 x64 10.0.22623
registry=https://registry.npmmirror.com