npm与git相关处理合集
1、解决下载包速度缓慢问题
1.查看当前的下包镜像源:
npm config get registry
2.将下包的镜像源切换为淘宝镜像源:
npm config set registry=https://registry.npm.taobao.org/
3.检查镜像是否下载成功:
npm config get registry
4.切换npm默认下载目录:
npm config set prefix "D:\Develop\npm"
npm config set cache "D:\nodejs\node_cache"
5.设置npm代理服务器:
npm config set registry http://10.35.83.20:4873/
2、npm版本与node版本问题
开发过程中有时候会遇到npm下载包的时候出错,有时候是npm版本过高,有时候是node版本过低,导致下载包出现错误
1)、终端出入 npm -v 和 node -v 查看本地 npm 版本和 node 版本
2)、查找 node 对应的 npm 版本 链接:https://nodejs.org/zh-cn/download/releases/ 比对本地 node 对应的 npm 版本
3)、安装指定版本的 npm: npm install npm@6.14.17 -g
4)、node下载路径:https://nodejs.org/en/
可以自行选择更换 node 版本或者是 npm 版本
卸载nodejs,(下载nodejs时npm也包含在内)重新安装nodejs;通过where node/where npm命令查看位置。然后把整个文件夹全删除,一定要删干净。再回到cmd中,输入node -v和npm -v确认已删除
3、报错:npm ERR! A complete log of this run can be found in
解决方法:
1)、找到项目里面的 package-lock.json 文件 ,删除该文件;
2)、重新执行: npm install/i
如果不想改变项目原有的 package-lock.json 文件等执行完毕之后,可以还原文件,不要提交到远程仓库
4、报错:Syntax Error: TypeError: Cannot read property ‘range’ of null
(1)、报错原因:
babel-eslint版本过高,可以在项目根目录中找到 package.json 文件,查看查看babel-eslint的版本
高版本插件一般容易出错,最稳妥的方法就是降低本地插件版本,使用稳定版进行开发
(2)解决方法:
1、在终端执行npm install babel-eslint@7.2.3 ,安装babel-eslint稳定版;
2、关闭项目,在本地删除node_modules文件夹,重新在编辑器打开项目;
3、注意在npm install 之前最好先清理下缓存,防止node_modules 出现某一些包错误时候,查不到原因 --> npm cache clean // npm cache clean --force
4、执行npm install,初始化项目;
5、重新启动项目。
5、eslint校验导致无法commit提交本地代码
开发过程中遇到eslint校验导致无法进行commit提交本地代码,如果校验文件不影响整体项目可执行:
git commit --no-verify -m "提交时的注释"