tonglin0325的个人主页

npm和yarn更换源

npm安装#

查看npm版本

1
2
npm -v

npm查看所有版本

1
2
npm view npm versions

npm更新到最新版

1
2
npm install -g npm

``查看npm当前镜像源

1
2
npm config get registry

设置npm镜像源为淘宝镜像

1
2
npm config set registry https://registry.npm.taobao.org/

遇到如下报错,是npm版本过低

1
2
Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at

需要ubuntu升级npm和node

1
2
3
4
5
6
7
8
9
10
11
12
13
node -v
v4.2.6
npm -v
3.5.2

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

node -v
v12.22.12
npm -v
6.14.16

npm安装项目依赖

1
2
npm install --dependencies

mac升级node,参考:Mac升级node14.17.2版本

清除nodejs的缓存

1
2
sudo npm cache clean -f

安装n模块

1
2
sudo npm install -g n

查看所有能安装的版本

1
2
npm view node versions

安装特定版本

1
2
sudo n 14.17.2

验证版本

1
2
3
node -v
v14.17.2

yarn安装#

参考:Yarn for mac 安装教程

查看yarn版本

1
2
yarn -v

yarn查看所有版本

1
2
npm view yarn versions

yarn更新到最新版<br />

1
2
npm install yarn@latest -g

yarn 升级指定版本

1
2
yarn upgrade v1.21.3

yarn 降低到指定版本(先卸载,再安装)

1
2
3
npm uninstall yarn -g
npm install -g yarn@1.3.2

查看yarn当前镜像源

1
2
yarn config get registry

设置yarn镜像源为淘宝镜像

1
2
yarn config set registry https://registry.npm.taobao.org/

镜像源地址

1
2
3
4
5
6
7
8
npm --- https://registry.npmjs.org/
cnpm --- https://r.cnpmjs.org/
taobao --- https://registry.npm.taobao.org/
nj --- https://registry.nodejitsu.com/
rednpm --- https://registry.mirror.cqupt.edu.cn/
npmMirror --- https://skimdb.npmjs.com/registry/
deunpm --- http://registry.enpmjs.org/

也可以在工程目录下添加 .npmrc 文件来指定该项目的源

1
2
registry=https://registry.npm.taobao.org/