Search code examples
javascriptnpmeslintnpxprettier-eslint

There was trouble creating the ESLint CLIEngine


There was trouble creating the ESLint CLIEngine. -
 'basePath' should be an absolute path

Trying to use eslint

$ npx prettier-eslint **/*.js

but getting:

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.

Solution

  • This is due to an issue with selecting the files with

    **/*.js

    A current UNIX workaround: use $PWD, i.e.

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

    This produced correct files as output

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

    This also applies to similar issues using package.json

    for instance having

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

    will also generate that error. On Unix this can currently be fixed with $PWD

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