WebStorm 2018.1.4 + ESLint: TypeError: this.CliEngine is not a constructor

WebStorm 2018.1.4 + ESLint: TypeError: this.CliEngine is not a constructor

我的配置是这样的

WebStorm 2018.1.4; ESLint 6.4;节点 12.8; npm 6.10.2; Windows8.1.

如何消除帖子标题中的错误?

这是一个代码示例。

import {
  GET_DAILY_SUCCESS,
  GET_HOURLY_SUCCESS,
  GET_MINUTE_SUCCESS
} from './types';
import {
  getDailyToUsd,
  getHourlyToUsd,
  getMinuteToUsd
} from '../api/cryptocompare';
import { setError } from './error';

export const getDaily = (fsym = 'BTC') => async dispatch => {
  try {
    const list = await getDailyToUsd(fsym);

    dispatch({
      type: GET_DAILY_SUCCESS,
      currency: fsym,
      list
    });
  } catch(err) {
    dispatch(setError(err.Message));
  }
};

WEB-38922 已在 2019.1.3 中修复。 问题出在 ESLint 版本 6.x 上。如果升级 Webstorm 不适合你,你必须降级到 ESLint 版本 5:

npm install --save-dev eslint@5

更新:如果您在使用 ESLint 8 时看到类似错误,请确保升级到支持它的版本 2021.2.2(参见 WEB-52236

这是另一个 solution from Dmitry Babenko,它可以让您使用 ESLint 6.x 和 WebStorm 的后备许可证:

  • Wait for the this.CliEngine is not a constructor balloon to appear and click "Details"
  • Follow the first link in the stack-trace to eslint-plugin.js file
  • Find the following line at the top:
    this.CliEngine = require(this.basicPath + "lib/cli-engine");
    And replace it with the following one:
    this.CliEngine = require(this.basicPath).CLIEngine;
  • Restart IDEA

我正在使用 Webstorm2021.2.1,我发现 eslint@8.0.0 与它不兼容。 这对我有用:

yarn add -D eslint@7.14.0

在我的 Webstorm 2021.2 中有一个稍微不同的错误 this.CliEngineCtor is not a constructor

这与更新eslint到8.0.1有关。

解决方法:更新WebStorm至最新版本2021.2.2或更高版本

Dabrule 答案外:

对于 eslint v8 替换此行:

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

到那个:

this.cliEngineCtor = requireInContext(eslintPackagePath + "lib/cli-engine").CLIEngine;

文件位置,例如RubyMine(WebStorm应该类似):
RubyMine-2021.1.3/plugins/JavaScriptLanguage/languageService/eslint/bin/eslint-plugin.js

升级到较新版本将解决此错误。

如您所见,该问题已在 2019.1.3 中解决

WEB-38922 - 在 2019.1 中使用 ESLint v6 进行 Linting 失败并出现错误 'TypeError: this.cliEngine is not a constructor'https://youtrack.jetbrains.com/issue/WEB-38922

对于 mac 用户,您可以打开: /Applications/PhpStorm.app/Contents/plugins/JavaScriptLanguage/languageService/eslint/bin/eslint-plugin.js 然后正如 Johny Martin 提到的, 替换:

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

与:

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

然后重启IDE,就可以正常工作了:)