在pnpm monorepo项目中想要通过commitizen约束git commit提交规范。
- 执行
pnpm i commitizen -Dw - 执行commitizen初始化,如果执行下面命令
pnpx commitizen init cz-conventional-changelog -Dw
会遇到下面提示
Attempting to initialize using the npm package cz-conventional-changelog
npm ERR! Cannot read properties of null (reading 'matches')
npm ERR! A complete log of this run can be found in:
npm ERR! D:\MyData\AppData\npm-cache\_logs\2023-03-28T23_55_35_722Z-debug-0.log
Error: Command failed: npm install cz-conventional-changelog --save-dev
npm ERR! Cannot read properties of null (reading 'matches')
npm ERR! A complete log of this run can be found in:
npm ERR! D:\MyData\AppData\npm-cache\_logs\2023-03-28T23_55_35_722Z-debug-0.log
at checkExecSyncError (node:child_process:828:11)
at Object.execSync (node:child_process:899:15)
at init (E:\.pnpm-store\v3\tmp\dlx-25372\node_modules\.pnpm\commitizen@4.3.0\node_modules\commitizen\dist\commitizen\init.js:1024:28)
at Object.bootstrap (E:\.pnpm-store\v3\tmp\dlx-25372\node_modules\.pnpm\commitizen@4.3.0\node_modules\commitizen\dist\cli\commitizen.js:30:30)
at Object.<anonymous> (E:\.pnpm-store\v3\tmp\dlx-25372\node_modules\.pnpm\commitizen@4.3.0\node_modules\commitizen\bin\commitizen.js:2:38)
解决方法,使用pnpm安装依赖,执行的时候加上参数--pnpm
pnpx commitizen init cz-conventional-changelog --pnpm -Dw
参考commitizen仓库
如果是monorepo项目,还会遇到下面的报错
Attempting to initialize using the npm package cz-conventional-changelog
Error: Command failed: pnpm add cz-conventional-changelog --save-dev
at checkExecSyncError (node:child_process:828:11)
at Object.execSync (node:child_process:899:15)
at init (E:\.pnpm-store\v3\tmp\dlx-3284\node_modules\.pnpm\commitizen@4.3.0\node_modules\commitizen\dist\commitizen\init.js:1024:28)
这个是因为在跟目录安装依赖需要加上-w
解决方法:
在根目录新建.npmrc,加上下面配置
ignore-workspace-root-check = true