报错发生时机

在给vue3项目添加eslint的时候,安装完依赖,并且在package.json中的scripts配置了eslint检测的命令之后执行检测命令,发生如下报错:

Oops! Something went wrong! :(

ESLint: 7.32.0

Error [ERR_REQUIRE_ESM]: require() of ES Module D:...\management-master\.eslintrc.js from D:...\management-master\node_modules\@eslint\eslintrc\lib\config-array-factory.js not supported.
.eslintrc.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 rename .eslintrc.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 D:...\management-master\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

解决:

按照报错,打算把根目录下的.eslintrc.js改为.eslintrc.cjs,改完之后确实能够执行了,但是.eslintrc.cjs文件一直显示报错,官方有建议几种文件的格式,这里建议直接写为.eslintrc,里面用一个大对象{}将所有的配置写在里面通过json的写法,即:

{
   "root": true,
   ...
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐