关于ESlint报错TypeError this.cliEngine is not a constructor解决方案亲测有效

webstorm关于ESlint报错TypeError: this.cliEngine is not a constructor以及Module Error (from ./node_modules/eslint-loader/index.js):的解决方案

1.问题描述:
  • 最近遇到一个不常遇到的问题:在webstorm上面运行配置了ESlintvue项目,项目刚跑起来是正常的,但是一开发就会报错,不论是添加、修改、删除代码,还是新增vue文件都会报下面两个错误:

  • (1)Failed to compile.

    ./src/components/test.vue
    Module Error (from ./node_modules/eslint-loader/index.js):

  • (2)TypeError: this.cliEngine is not a constructor

  • 刚开始我以为是eslint-loader加载插件出了问题,然后按照网上的方法重装ESlint,并且重新配置ESlint等等,都试了但是无济于事,后面我把目光集中在第二个问题上,把第二个问题解决后,第一个问题也没有了,项目恢复正常!(其实这个问题是webstorm本地ESlint版本过低导致的)下面分享一下我的解决方案:

2.解决方案:
  • 1.找到webstorm安装目录下ESlint的配置文件(可以参考下我的索引:C:\program files\WebStorm 2018.3.2\plugins\JavaScriptLanguage\languageService\eslint\bin\eslint-plugin.js)。

  • 2.找到文件后,然后对eslint-plugin.js进行重新配置(先对cliEngine进行关键词搜索,找到下面代码,copy配置后的代码即可):

  • // 配置前
    // this.cliEngine = require(packagePath + "lib/cli-engine")
    // 配置后
    this.cliEngine = require(packagePath + "lib/cli-engine").CLIEngine;;
    

版权声明:本文为qq_34917408原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。