4.1 配置package.json 的type:module后, babel文件引起的vue-cli 运行报错

1.起因:配置package.json 的type:module

参考:https://stackoverflow.com/questions/61257559/using-native-ecmascript-modules-in-babeljs-config

2.问题(提示希望异步使用babel)

解决

将babel.config.js文件改为babel.config.cjs文件

参考:https://stackoverflow.com/questions/61257559/using-native-ecmascript-modules-in-babeljs-config

3.cjs文件

总结为一句话:.mjs文件总是以 ES6 模块加载,.cjs文件总是以 CommonJS 模块加载,.js文件的加载取决于package.json里面type字段的设置。

参考:阮一峰博客:https://www.ruanyifeng.com/blog/2020/08/how-nodejs-use-es6-module.html

参考:https://zhuanlan.zhihu.com/p/51457550

原文地址:https://www.cnblogs.com/xjt31/p/14604882.html