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

相关推荐
一舍予1 小时前
八股文-js篇
开发语言·前端·javascript
大卫小东(Sheldon)2 小时前
GIM: 调用AI自动生成git提交消息的工具
git·rust
鸡鸭扣2 小时前
DRF/Django+Vue项目线上部署:腾讯云+Centos7.6(github的SSH认证)
前端·vue.js·python·django·腾讯云·drf
龙井茶Sky2 小时前
验证码与登录过程逻辑学习总结
前端·登录·验证码
Edward Nygma2 小时前
springboot3+vue3融合项目实战-大事件文章管理系统-更新用户密码
android·开发语言·javascript
sunbyte3 小时前
Three.js + React 实战系列 - 职业经历区实现解析 Experience 组件✨(互动动作 + 3D 角色 + 点击切换动画)
javascript·react.js·3d
程序设计实验室3 小时前
如何清理误提交到git的历史大文件?
git
2401_831943323 小时前
Element Plus对话框(ElDialog)全面指南:打造灵活弹窗交互
前端·vue.js·交互
计算机学姐3 小时前
基于SpringBoot的在线教育管理系统
java·vue.js·spring boot·后端·mysql·spring·mybatis
strongwyy3 小时前
DA14585墨水屏学习(2)
前端·javascript·学习