npm 和yarn的安装和使用方法

npm 和yarn的安装和使用方法

一、npm安装

bash 复制代码
gnvm install 10.24.1
gnvm use 10.24.1
gnvm ls
gnvm npm global

#npm i 报错问题error Unexpected token '.'

#解决办法 node降级安装为node 14.21.3版本 npm 6.14.18版本

#gnvm search 14..

bash 复制代码
gnvm install 14.21.3
gnvm ls
gnvm use 14.21.3
gnvm npm global

#npm install 报错问题error cb() never called!

#解决办法:node降级为node 10.24.1 npm 6.14.12

#gnvm search 10..

bash 复制代码
gnvm install 10.24.1
gnvm use 10.24.1
gnvm ls
gnvm npm global

二、yarn 安装

#Yarn是由Facebook、Google、Exponent 和 Tilde 联合推出了一个新的 JS 包管理工具 ,

#正如官方文档中写的,Yarn 是为了弥补 npm 的一些缺陷而出现的。

#关于频繁变动 node 版本,建议使用 gnvm/nvm 管理,就像 python 用 conda

bash 复制代码
npm install -g yarn
yarn -v

三、设置数据源

bash 复制代码
#set source taotao
yarn config set registry https://registry.npm.taobao.org -g
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g
yarn config get registry

npm config set registry https://registry.npm.taobao.org
npm config get registry

#set source npm mirror
npm config set registry https://registry.npmmirror.com
npm config get registry

yarn config set registry https://registry.npmmirror.com -g
yarn config get registry

四、yarn和npm命令对照

bash 复制代码
npm                            yarn
npm install                    yarn
npm install react --save       yarn add react
npm uninstall react --save     yarn remove react
npm install react --save-dev   yarn add react --dev
npm update --save              yarn upgrade

五、yarn下载依赖包

bash 复制代码
yarn
yarn -v

六、npm下载依赖包

bash 复制代码
npm install
npm -v

本blog地址:https://blog.csdn.net/hsg77

相关推荐
JaredYe8 小时前
纯 Node.js 编译 LaTeX:无需 TeX Live、无需宏包管理的工程级方案(node-latex-compiler)
node.js·latex·tectonic
_Kayo_12 小时前
Node.JS 学习笔记8
笔记·学习·node.js
six+seven13 小时前
Node.js内置模块fs
前端·node.js
wuhen_n13 小时前
Webpack vs Vite:前端构建工具对比
前端·webpack·node.js·vite
Gogo81614 小时前
Node.js 后端架构的“隐秘角落”:从 Fastify 引擎到类型系统的博弈
架构·node.js
本妖精不是妖精14 小时前
CentOS 7 安装 Node.js v18.x 完整教程
linux·centos·node.js
摇滚侠1 天前
Node.js 零基础教程,Node.js 和 NPM 的安装与使用
前端·npm·node.js
Ashley_Amanda2 天前
Node.js 服务搭建:从零到部署的生产级指南
node.js
天远云服2 天前
Node.js实战:天远车辆出险查询API接口调用流程、代码接入与场景应用
大数据·node.js
摇滚侠2 天前
安装完 node.js 以后,需不需要修改全局安装包的目录,我觉的不需要修改。网上有很多教程让修改全局包安装目录和配置环境变量,我觉的这两步都多余。
node.js