npm和yarn更换源
npm安装
查看npm版本
npm -v
npm查看所有版本
npm view npm versions
npm更新到最新版
npm install -g npm
查看npm当前镜像源
npm config get registry
设置npm镜像源为淘宝镜像
npm config set registry https://registry.npm.taobao.org/
遇到如下报错,是npm版本过低
Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at
需要ubuntu升级npm和node
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安装项目依赖
npm install --dependencies
mac升级node,参考:Mac升级node14.17.2版本
清除nodejs的缓存
sudo npm cache clean -f
node版本管理
1.使用n模块
安装n模块
sudo npm install -g n
查看所有能安装的版本
npm view node versions
安装特定版本
sudo n 14.17.2
验证版本
node -v v14.17.2
查看安装的node版本
n list node/14.17.2 node/18.15.0
切换系统node版本
$ sudo node -v v18.15.0 $ sudo n 14.17.2 copying : node/14.17.2 installed : v14.17.2 (with npm 6.14.13) $ sudo node -v v14.17.2
临时使用某个node版本
n use 18.15.0
2.使用nvm模块
pnpm安装
brew install pnpm
参考:https://pnpm.io/zh-TW/next/installation
yarn安装
查看yarn版本
yarn -v
yarn查看所有版本
npm view yarn versions
yarn更新到最新版
npm install yarn@latest -g
yarn 升级指定版本
yarn upgrade v1.21.3
yarn 降低到指定版本(先卸载,再安装)
npm uninstall yarn -g npm install -g yarn@1.3.2
查看yarn当前镜像源
yarn config get registry
设置yarn镜像源为淘宝镜像
yarn config set registry https://registry.npm.taobao.org/
镜像源地址
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 文件来指定该项目的源
registry=https://registry.npm.taobao.org/
本文只发表于博客园和tonglin0325的博客,作者:tonglin0325,转载请注明原文链接:https://www.cnblogs.com/tonglin0325/p/5950968.html