vite创建项目中,为什么eslint 和 prettier 配置文件不能是 .js 文件,必须是.cjs 文件

449 阅读1分钟

首先项目被创建为 ES module。因为在 package.json,中 type: module,所有 .js 文件声明为 ES 模块 。

eslint.js, prettier.js 被默认为使用了 ES module 规范,因为是.js 文件。

eslint.js, prettier.js 重命名为以 .cjs 结尾 会告诉 node.js 它使用了 CommonJS 规范。 就将 "type": "commonjs",package.json 将所有 .js 文件视为 CommonJS