安装commitlint时候遇到的问题

git地址:
https://github.com/conventional-changelog/commitlint#getting-started


项目是一个新项目,vue3 + vite + ts, 配置了ESlint。
但是按照文档安装完commitlint之后,遇到以下问题:

  1. “⚠ Some of your tasks use git add command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.”

⚠ 一些任务使用了 git add 命令。请从配置中移除它,因为所有由任务进行的修改都会自动添加到 Git 提交索引中。

这个问题是因为配置ESlint的时候,在 package.json 文件里面的 lint-staged 中配置了 'git add ', 和新安装的 commitlint 插件冲突了,这俩都会自动添加到 Git 提交索引中。所以,删掉 lint-staged的这个配置就可以了。
在这里插入图片描述
2. 第二个问题是提示
D:\study\shop-admin-with-vue3-vite-ts\node_modules\ts-node\dist\index.js:851
return old(m, filename);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module D:\study\shop-admin-with-vue3-vite-ts\commitlint.config.js from D:\study\shop-admin-with-vue3-vite-ts\node_modules\cosmiconfig\dist\loaders.js not supported.
commitlint.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which declares all .js files in that package scope as ES modules.

这个问题是因为,我在 package.json 指定了type是module, 使用的ES 模块的规范,提交commit的时候,校验报错了。
在这里插入图片描述
原因在于配置commitlint.config.js文件的时候,使用的是 CommonJS 模块规范。
在这里插入图片描述
解决:改成ES规范即可。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_40887836/article/details/132071532