创建 ESLint CLIEngine 时出现问题

Posted

技术标签:

【中文标题】创建 ESLint CLIEngine 时出现问题【英文标题】:There was trouble creating the ESLint CLIEngine 【发布时间】:2020-05-23 00:09:44 【问题描述】:
There was trouble creating the ESLint CLIEngine. -
 'basePath' should be an absolute path

尝试使用 eslint

$ npx prettier-eslint **/*.js

但得到:

prettier-eslint [ERROR]: There was trouble creating the ESLint CLIEngine.
prettier-eslint-cli [ERROR]: There was an error formatting "test/fizzBuzz.test.js":
    AssertionError [ERR_ASSERTION]: 'basePath' should be an absolute path.

【问题讨论】:

【参考方案1】:

这是由于选择文件时出现问题

**/*.js

当前的 UNIX 解决方法:使用 $PWD,即

$ npx prettier-eslint $PWD/'**/*.js'

这产生了正确的文件作为输出

回复:https://github.com/prettier/prettier-eslint-cli/issues/208

这也适用于使用package.json的类似问题

例如拥有

"lint": "eslint . && prettier-eslint --list-different **/*.js",
"format": "prettier-eslint --write **/*.js"

也会产生该错误。 在 Unix 上,目前可以使用 $PWD

修复此问题
"lint": "eslint . && prettier-eslint --list-different $PWD/'**/*.js'",
//                                                    /|\
"format": "prettier-eslint --write $PWD/'**/*.js'"
//                                 /|\

【讨论】:

以上是关于创建 ESLint CLIEngine 时出现问题的主要内容,如果未能解决你的问题,请参考以下文章

WebStorm 2018.1.4 + ESLint: TypeError: this.CliEngine 不是构造函数

webstorm报错TypeError: this.cliEngine is not a constructor

尝试运行 ESLint 脚本时出现“SyntaxError: Unexpected token ”

尝试部署 Firebase 功能时出现 ESLint 错误

尝试 lint Angular 模板时出现 ESLint 错误

尝试部署功能 Firebase 时出现 ESLint 错误