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

相关推荐
人工智能训练师19 小时前
Ubuntu22.04如何安装新版本的Node.js和npm
linux·运维·前端·人工智能·ubuntu·npm·node.js
Seveny0719 小时前
pnpm相对于npm,yarn的优势
前端·npm·node.js
huangql5201 天前
npm 发布流程——从创建组件到发布到 npm 仓库
前端·npm·node.js
荣达1 天前
koa洋葱模型理解
前端·后端·node.js
csdn_aspnet1 天前
Windows Node.js 安装及环境配置详细教程
windows·node.js
风若飞1 天前
npm ERR! code CERT_HAS_EXPIRED
前端·npm·node.js
csdn_aspnet1 天前
Windows、Linux 系统 nodejs 和 npm 版本更新及错误修复
linux·windows·npm·node.js
北城笑笑1 天前
NodeJS 8 ,从 0 到 1:npm 包发布与更新全流程指南( 含多场景适配与踩坑总结 )
前端·npm·node.js·github
码码哈哈0.01 天前
npm : 无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚
前端·npm·node.js
歪歪1002 天前
webpack 配置文件中 mode 有哪些模式?
开发语言·前端·javascript·webpack·前端框架·node.js