webstorm报错cliEngineCtor is not a constructor this.options.parse is not a function at ESLintPlugin

问题描述:
使用的webStorm 版本号为:2021.1.1 和 2020.3(同事的),eslint 版本号为:8.28.0 出现报错如下: 

TypeError: this.cliEngineCtor is not a constructor

TypeError: this.cliEngineCtor is not a constructor
    at ESLintPlugin.invokeESLint (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js:104:25)
    at ESLintPlugin.getErrors (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js:83:21)
    at ESLintPlugin.onMessage (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js:57:64)
    at Interface. (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\jsLanguageServicesImpl\js-language-service.js:105:39)
    at Interface.emit (node:events:513:28)

找到解决办法说是 eslint 版本高了的问题,需要降低到 8.22 及以下,
解决:
卸载 eslint
安装 [email protected] -D --exact
删除 package-lock.json
执行 npm install

上面的报错解决了,但是出现了新的报错,如下


问题解决能正常运行 eslint 进行格式化代码

Problem with ESLint reformatting: App.tsx: TypeError: this.options.parse is not a function  TypeError: this.options.parse is not a function at ESLintPlugin.invokeESLint (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js:90:70) at ESLintPlugin.fixErrors (E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js:86:21) at ESLintPlugin.onMessage (E:\WebStorm

找到解决方法说要么升级 webstorm 版本到 2021.2.2 要么需要改 webstorm 中的 eslint-plugin.js 文件,我自己采用修改 eslint-plugin.js 文件的方法
打开webstorm 安装目录,找到路径: 
E:\WebStorm 2021.1.1\plugins\JavaScriptLanguage\languageService\eslint\bin打开 eslint-plugin.js, 修改 this.cliEngineCtor 如下:

// 修改前:
this.cliEngineCtor = requireInContext(eslintPackagePath + "lib/api", state.packageJsonPath).CLIEngine;

// 修改后:
// this.cliEngineCtor = requireInContext(eslintPackagePath + "lib/api", state.packageJsonPath).CLIEngine;
this.cliEngineCtor = requireInContext(eslintPackagePath + "lib/cli-engine").CLIEngine;

参考文章:
https://blog.csdn.net/weixin_43928813/article/details/126891996
https://blog.csdn.net/lw001x/article/details/123891939

 

你可能感兴趣的:(报错,前端,javascript,html5)