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

相关推荐
百万蹄蹄向前冲4 小时前
不会邮件合并,就用代码KoWord
node.js·产品·trae
程序猿小D7 小时前
第25节 Node.js 断言测试
后端·node.js·log4j·编辑器·vim·apache·restful
不想说话的麋鹿10 小时前
《NestJS 实战:RBAC 系统管理模块开发 (二)》:菜单与权限路由设计
前端·node.js·全栈
Avan_菜菜10 小时前
Nuxt3 中使用 pnpm 安装的 NuxtImg 使用会提示找不到图片
前端·npm·nuxt.js
抠脚小弟12 小时前
实现vue组件库并发布npm上使用流程
前端·vue.js·npm
HarryHY13 小时前
检查项目中的依赖是否有更新——npm outdated
前端·npm·node.js
树獭叔叔14 小时前
从零开始Node之旅——Nest.js 模块系统(Modules)
后端·node.js
non_hana15 小时前
Vite Dev Server 构建原理
node.js·vite
non_hana15 小时前
一些 linter & formatter 配置最佳实践
typescript·node.js·eslint
持久的棒棒君1 天前
npm安装electron下载太慢,导致报错
前端·electron·npm