You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yarn v2环境配置CommitLint与Husky提交时报错怎么解决?

Yarn 2 项目 CommitLint + Husky 提交报错修复方案
  • 移除无效命令参数
    --no-install为Yarn 1.x、npx的专属参数,Yarn 2(Berry)不支持该参数,这是报错的核心原因。直接修改项目.husky/commit-msg钩子文件内容为:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit "$1"
  • 安装兼容版本的依赖
    Node 14 LTS 无法适配最新版的CommitLint、Husky,执行以下命令安装兼容版本的核心依赖:
yarn add @commitlint/cli@17 @commitlint/config-conventional@17 husky@8 -D
  • 检查CommitLint配置
    确保项目根目录存在.commitlintrc.js配置文件,基础配置参考:
module.exports = {
  extends: ['@commitlint/config-conventional']
}
  • PnP模式兼容处理(可选)
    如果项目开启Yarn 2默认的PnP模式仍提示找不到命令,可在根目录.yarnrc.yml中添加配置切换为node_modules模式:
nodeLinker: node-modules

修改后执行yarn install重新安装依赖即可生效。

内容的提问来源于stack exchange,提问作者LocTran016

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.17 02:54:05