go to index

git提交ERROR This version of pnpm requires at least Node.js v16.4错误解决方案

read time 2 min read
git husky 规范

概述

在使用 Git 提交时,可能会遇到以下错误提示:

plaintext
ERROR: This version of pnpm requires at least Node.js v16.14
The current version of Node.js is v16.10.0
Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.
husky - pre-commit hook exited with code 1 (error)

该错误表示当前安装的 Node.js 版本低于 pnpm 所需的最低版本要求。本文将介绍如何解决这一问题。

问题原因

此错误主要是因为 husky 插件在提交前会进行一些校验,确保项目依赖和环境配置符合要求。如果 Node.js 版本不符合 pnpm 的最低要求,就会触发上述错误。

解决办法

方法一:临时关闭校验

如果你需要快速提交而不想立即解决版本问题,可以临时关闭 husky 校验。

示例命令

bash
git commit -m '提交信息' --no-verify

注意:这种方法适用于紧急情况,但不推荐长期使用,建议尽快升级 Node.js 版本以符合项目要求。

方法二:关闭 Git Hook

如果你希望完全禁用 Git Hook(例如 husky),可以执行以下命令:

示例命令

bash
git config --unset core.hooksPath

注意:这种方法较为激进,会禁用所有 Git Hook,可能影响项目的自动化流程,建议谨慎使用。