.eslintrc.js is treated as an ES module file as it is a .js file whose nearest parent package.json c
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
报错发生时机
在给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,
...
}
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
4 个月前
8c391e04
6 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)