1. 限制项目的node版本
- package.json 添加
engines字段, 对npm install 无效,所以推荐使用 yarn
"engines": {
"node": "14.18.1"
}
当你的同事使用的不是 node v14.18.1,在执行 yarn 相关命令时,控制台会给出error提示
error dc_v2_fe_el_ts@0.1.0: The engine "node" is incompatible with this module. Expected version "14.18.1". Got "16.14.0"
- 安装
nvm如果之前已经安装过node,需要卸载,参考mac环境搭建
.nvmrc 里写上对应版本号
v14.18.1
目的是简化命令, 使用 nvm use 即可切换到 v14.18.1
2. 限制包管理器
由于 engines 字段对npm无效,并且npm install 有时候安装依赖失败,推荐换成 yarn
添加如下配置,强制只能使用 yarn, 无需安装npm-client-limit
"scripts": {
"preinstall": "npx npm-client-limit yarn",
}
当执行 npm install 时,给出错误提示