一个文件中同时存在 module.exports 和 export 报错

一个文件中同时存在module.exports 和export报错

原因:

  • module.exports 是cjs的规范
  • export 是esm的规范

es6之前,js没有自己的模块规范,因此node设计了CommonJS规范即cjs,如果一个文件是以cjs规范书写的,那大概率是用在node环境中的。只要加个编译器就可以打包转换成各种格式。但如果一个文件里同时出现了esm和cjs,那编译器就无法解析了

posted @ 2022-12-06 22:18  轻风细雨_林木木  阅读(4)  评论(0编辑  收藏  举报