【开发问题记录】执行 git cz 报require() of ES Module…… 错误

文章目录

1、问题

在对 commitizen 进行完,一系列的初始化以后 , 对代码进行 提交 到暂存区,然后要提交到 本地仓库 的报错

然后因为安装了 commitizen 所以是想用 git cz 进行提交的, 执行命令的时候确报错了

shell 复制代码
require() of ES Module F:\个人项目\dida_client_pc\.cz-config.js from F:\个人项目\dida_client_pc\node_modules\.pnpm\find-config@1.0.0\node_modules\find-config\src\find-config.js not supported..cz-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.Instead either rename .cz-config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in F:\个人项目\dida_client_pc\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

2、解决

其实看这个报错的大概意思,也能猜到,是 module 和 commonjs 相互转化的问题

这个项目是 vue3 项目,vue3默认都是 module 的, 所以还得从这个 插件 下手,进行解决 ,然后在 GitHub上找到了这个

解决方案

1、把 .cz-config.js 重命名 为 .cz-config.cjs

2、修改 package.json 文件 ,增加这个 cz-customizable 的配置

js 复制代码
  "config": {
    "cz-customizable": {
      "config": ".cz-config.cjs"
    }
  }

3、参考链接

相关推荐
清汤饺子7 小时前
OpenClaw 本地部署教程 - 从 0 到 1 跑通你的第一只龙虾
前端·javascript·vibecoding
颜酱7 小时前
图的数据结构:从「多叉树」到存储与遍历
javascript·后端·算法
爱吃的小肥羊9 小时前
比 Claude Code 便宜一半!Codex 国内部署使用教程,三种方法任选一!
前端
IT_陈寒10 小时前
SpringBoot项目启动慢?5个技巧让你的应用秒级响应!
前端·人工智能·后端
树上有只程序猿11 小时前
2026低代码选型指南,主流低代码开发平台排名出炉
前端·后端
橙某人11 小时前
LogicFlow 小地图性能优化:从「实时克隆」到「占位缩略块」!🚀
前端·javascript·vue.js
高端章鱼哥11 小时前
为什么说用OpenClaw对打工人来说“不划算”
前端·后端
大脸怪11 小时前
告别 F12!前端开发者必备:一键管理 localStorage / Cookie / SessionStorage 神器
前端·后端·浏览器
Mr_Mao11 小时前
我受够了混乱的 API 代码,所以我写了个框架
前端·api
小徐_233311 小时前
向日葵 x AI:把远程控制封装成 MCP,让 AI 替我远程控制设备
前端·人工智能