以下为 pnpm 镜像
npm 安装 pnpm
npm install -g pnpm
查看是否安装成功
pnpm -v
常用命令
# 创建一个 package.json 文件
pnpm init
# 安装软件包及其依赖的任何软件包(如果 workspace 有配置会优先从 workspace 安装)
pnpm add <pkg>
# 安装项目所有依赖
pnpm install
# 更新软件包的最新版本
pnpm update
# 移除项目依赖
pnpm remove
# 运行脚本
pnpm run
# 以一个树形结构输出所有的已安装 package 的版本及其依赖
pnpm list
查看当前镜像
pnpm config get registry
设为淘宝镜像
淘宝镜像源一(推荐)
pnpm config set registry https://registry.npmmirror.com/
淘宝镜像源二
pnpm config set registry http://registry.npm.taobao.org/
设为官方默认镜像
pnpm config set registry https://registry.npmjs.org
设置环境目录
# pnpm 全局 bin 路径
pnpm config set global-bin-dir "D:\Program\nodejs\pnpm\.pnpm-bin-dir"
# pnpm 全局缓存路径
pnpm config set cache-dir "D:\Program\nodejs\pnpm\.pnpm-cache"
# pnpm 全局安装路径
pnpm config set global-dir "D:\Program\nodejs\pnpm\.pnpm-global"
# pnpm 创建 pnpm-state.json 文件的目录
pnpm config set state-dir "D:\Program\nodejs\pnpm\.pnpm-state"
# pnpm 全局仓库路径(类似 .git 仓库)
pnpm config set store-dir "D:\Program\nodejs\pnpm\.pnpm-store"
配置环境变量
在 path 环境变量中添加配置 pnpm 全局 bin,如下图:
D:\Program\nodejs\pnpm\.pnpm-bin-dir
以下为 yarn 镜像
npm 安装 yarn
npm install -g yarn
npm 卸载 yarn
npm uninstall -g yarn
查看是否安装/卸载成功
yarn -v
常用命令
# 初始化项目
yarn init
# 装包
yarn add packagename
yarn add packagename --dev
# 更新包
yarn upgrade packagename
# 删除包
yarn remove packagename
# 安装所有包
yarn
yarn install
# 发布包
yarn publish
# 查看包的缓存列表
yarn cache list
# 全局安装包 == npm -g
yarn global
查询当前镜像
yarn config get registry
设置为淘宝镜像
淘宝镜像源一(推荐)
yarn config set registry https://registry.npmmirror.com/
淘宝镜像源二
yarn config set registry http://registry.npm.taobao.org/
设置为官方默认镜像
yarn config set registry https://registry.yarnpkg.com/
以下为 npm 镜像
npm 查询当前镜像
npm get registry
npm 设置为淘宝镜像
淘宝镜像源一(推荐)
npm config set registry https://registry.npmmirror.com/
淘宝镜像源二
npm config set registry http://registry.npm.taobao.org/
npm 设置为官方默认镜像
npm config set registry https://registry.npmjs.org/
npm 使用 nrm 源管理器切换镜像站点
安装 nrm 源管理器
npm install -g nrm
查看站点列表
nrm ls
npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/
切换镜像站点到淘宝源
nrm use taobao
错误提示
① 有时候会遇到以下报错,可能是因为镜像问题(官方默认镜像有时访问不了)
info There appears to be trouble with your network connection. Retrying...
② 当 npm install 时遇到报错 ERESOLVE unable to resolve dependency tree 的问题
方案一:版本降级(原版本是 16.20.1,降级为 14.21.3)
方案二:npm install -f [带上 --force 参数(简写 -f)告诉 npm 强制安装]