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

相关推荐
Amos_Web2 小时前
Rspack 源码解析 (1) —— 架构总览:从 Node.js 到 Rust 的跨界之旅
前端·rust·node.js
badhope2 小时前
前端已死?前端角色演进的四维技术证据链(2026年实证)
react.js·django·node.js
飞扬rdh4 小时前
npm插件的开发详细流程
npm
badhope4 小时前
Ollama、vLLM、Transformers等本地AI平台终极乱斗:手把手教你选对“高达”驾驶舱,拒绝选择困难症!
react.js·程序员·node.js
xw-busy-code4 小时前
npm 包管理笔记整理
前端·笔记·npm
别看我只是一直狼5 小时前
一套能直接复用的 Playwright 提示词大全
node.js
Arya_aa6 小时前
1.卸载node.js才可以下载nvm,使用nvm更高级,可以指定下载node版本,开发javaweb项目
node.js
winfredzhang8 小时前
从后端架构到移动端体验:拆解一个优雅的 Node.js 轻量级媒体管理系统
架构·node.js·媒体
吴声子夜歌8 小时前
Node.js——npm包管理器
前端·npm·node.js
xw-busy-code1 天前
npm私服搭建学习笔记
笔记·学习·npm·npm 私服