报错发生时机
在给vue3项目添加eslint的时候,安装完依赖,并且在package.json中的scripts配置了eslint检测的命令之后执行检测命令,发生如下报错:文章来源:https://www.toymoban.com/news/detail-532645.html
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的写法,即:文章来源地址https://www.toymoban.com/news/detail-532645.html
{
"root": true,
...
}
到了这里,关于.eslintrc.js is treated as an ES module file as it is a .js file whose nearest parent package.json c的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!