【开发问题记录】执行 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、参考链接

相关推荐
Asize8 分钟前
HTML5 Canvas 基础:从按帧动画到 ECharts 数据可视化
前端·javascript·canvas
默_笙11 分钟前
🎄 后端给我一堆扁平数据,我 10 行代码把它变成了树
前端·javascript
Mahut13 分钟前
我用 Electron + FFmpeg 做了一个本地视频处理工作站 ClipForge
前端·ffmpeg·electron
前端Hardy17 分钟前
又一个 AI 神器火了!
前端·javascript·后端
锋行天下21 分钟前
我试图优化 Vite 的拆包,结果首屏慢了 10 倍
前端·vue.js·架构
PBitW39 分钟前
GPT训练我的第二天,我表示不过如此!!!😕😕😕
前端·javascript·面试
用户99045017780091 小时前
学习了AI修图,我把自己闲鱼出租房照片整成airbnb风格了
前端
kyriewen2 小时前
白宫直接给 OpenAI 下了限制令,GPT-5.6 不能随便放出来了
前端·javascript·面试
PedroQue993 小时前
Vite插件v0.2.6:架构优化与自动化升级
前端·vite
threerocks4 小时前
什么?我连 A2A、MCP 都没学会,现在又来了 AG-UI、A2UI.
前端·aigc·ai编程