question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path

See original GitHub issue

Windows Node v12.13.0 npm v6.13.6 eslint 6.8.0 Parser: @typescript-eslint/parser Bash terminal

eslint config:

"use strict";
const allExtensions = [".ts", ".tsx", ".d.ts", ".js", ".jsx"];
module.exports = {
    env: {
        "browser": true,
        "es6": true,
    },
    parser: "@typescript-eslint/parser",
    parserOptions: {
        project: "./tsconfig.json",
        sourceType: "module",
    },
    plugins: [
        "import",
        "@typescript-eslint",
        "@typescript-eslint/tslint",
    ],
    settings: {
        "import/extensions": allExtensions,
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx", ".d.ts"],
        },
        "import/resolver": {
            "node": {
                "extensions": allExtensions,
            },
        },
    },
    rules: {
     
        "import/no-deprecated": "warn",
        "@typescript-eslint/no-unused-vars": "error",
        "@typescript-eslint/tslint/config": [
            "warn",
            {
                "rules": {
                    "deprecation": true,
                },
            },
        ],
    },
};

I’m currently using a globally installed npm package (call it foo cli) that wraps eslint. I have a workspace in c:\src\myproject. foo cli has an internal reference to eslint 6.8.0. When I run ap lint from c:\src\myproject, foo cli invokes eslint with some default parameters, and I get the error from the bug title. Here’s the raw output:

/c/myproject (master)
$ ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path.
    at IgnorePattern.getPatternsRelativeTo (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:210:9)
    at C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:42
    at Array.map (<anonymous>)
    at Function.createIgnore (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:31)
    at createConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:282:40)
    at ConfigArray.extractConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:452:33)
    at FileEnumerator._isIgnoredFile (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:479:24)
    at FileEnumerator._iterateFilesRecursive (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:407:38)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:251:49)

I believe the problem exists in ignore-pattern.js and was introduced in this pull request: https://github.com/eslint/eslint/pull/12274/files

If I add some debug logging to IgnorePattern.getCommonAncestorPath:

function getCommonAncestorPath(sourcePaths) {
    let result = sourcePaths[0];

    for (let i = 1; i < sourcePaths.length; ++i) {
        const a = result;
        const b = sourcePaths[i];

        // Set the shorter one (it's the common ancestor if one includes the other).
        result = a.length < b.length ? a : b;

        // Set the common ancestor.
        for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
            if (a[j] !== b[j]) {
                result = a.slice(0, lastSepPos);
                break;
            }
            if (a[j] === path.sep) {
                lastSepPos = j;
            }
        }
    }
    console.log("**: ", { result: result, sep: path.sep, sourcePaths: sourcePaths }); // new line here
    return result || path.sep;
}

I see the following output:

/c/myproject (master)
$ ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
**:  {
  result: 'C:\\src\\myproject',
  sep: '\\',
  sourcePaths: [ 'C:\\src\\myproject' ]
}
**:  {
  result: 'C:\\src\\myproject',
  sep: '\\',
  sourcePaths: [ 'C:\\src\\myproject' ]
}
**:  {
  result: 'C:',
  sep: '\\',
  sourcePaths: [
    'C:\\src\\myproject',
    'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
  ]
}
AssertionError [ERR_ASSERTION]: 'newBasePath' should be an absolute path.
    at IgnorePattern.getPatternsRelativeTo (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:210:9)
    at C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:42
    at Array.map (<anonymous>)
    at Function.createIgnore (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\ignore-pattern.js:150:31)
    at createConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:282:40)
    at ConfigArray.extractConfig (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\config-array\config-array.js:452:33)
    at FileEnumerator._isIgnoredFile (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:479:24)
    at FileEnumerator._iterateFilesRecursive (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:407:38)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\eslint\lib\cli-engine\file-enumerator.js:251:49)

/c/myproject (master)
$

Notice the result: 'C:', - that is not considered a valid absolute path.

Interestingly enough, I can mitigate the problem by using windows cmd.exe and setting my current prompt to c:\ (lowercase, as opposed to C:\). Because c:\ != C:\, it works. See the output:

c:\src\myproject>ap lint
Running C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\node_modules\.bin\eslint.cmd **/*.ts --ignore-path C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintignore -c C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint\.eslintrc.json --resolve-plugins-relative-to C:\Users\drkestel\AppData\Roaming\npm\node_modules\@foocli\lint
**:  {
  result: 'c:\\src\\myproject',
  sep: '\\',
  sourcePaths: [ 'c:\\src\\myproject' ]
}
**:  {
  result: 'c:\\src\\myproject',
  sep: '\\',
  sourcePaths: [ 'c:\\src\\myproject' ]
}
**:  {
  result: '',
  sep: '\\',
  sourcePaths: [
    'c:\\src\\myproject',
    'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
  ]
}
**:  {
  result: '',
  sep: '\\',
  sourcePaths: [
    'c:\\src\\myproject',
    'C:\\Users\\drkestel\\AppData\\Roaming\\npm\\node_modules\\@foocli\\lint'
  ]
}

c:\src\myproject\Client\Index.ts
  66:5   warning  Missing return type on function                 @typescript-eslint/explicit-function-return-type
  67:17  error    'container' is assigned a value but never used  @typescript-eslint/no-unused-vars
  68:15  error    'id' is assigned a value but never used         @typescript-eslint/no-unused-vars

... more valid linting

I can also mitigate the problem by making the following code change to ignore-pattern.js:

function getCommonAncestorPath(sourcePaths) {
    let result = sourcePaths[0];

    for (let i = 1; i < sourcePaths.length; ++i) {
        const a = result;
        const b = sourcePaths[i];

        // Set the shorter one (it's the common ancestor if one includes the other).
        result = a.length < b.length ? a : b;

        // Set the common ancestor.
        for (let j = 0, lastSepPos = 0; j < a.length && j < b.length; ++j) {
            if (a[j] !== b[j]) {
                result = a.slice(0, lastSepPos);
                break;
            }
            if (a[j] === path.sep) {
                lastSepPos = j;
            }
        }
    }
    // this was the previous return statement
    // return result || path.sep;

    // new return statement
    let resolvedResult = result || path.sep;
    if (resolvedResult && resolvedResult.endsWith(":")) {
        resolvedResult = resolvedResult + path.sep;
    }
    return resolvedResult;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
kaicataldocommented, Feb 4, 2020

Thanks for the detailed bug report. This does seem like a bug to me. Looking at how paths work in WIndows in Microsoft’s documentation, it does look like we need to fix this algorithm to not remove the separator from C:, since "C:" is considered relative while "C:\\" is considered absolute.

1reaction
nickharriscommented, May 14, 2020

yup already using it 😃 thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: 'basePath' should be an absolute path. #208 - GitHub
no error is reported, but I want to support relative paths. When I use version 6.6.0 of eslint,also no error is reported;.
Read more >
There was trouble creating the ESLint CLIEngine
test.js": AssertionError [ERR_ASSERTION]: 'basePath' should be an absolute path.
Read more >
prettier - Bountysource
I have created a repository which reproduces the issue. There appears to be a bug within prettier-eslint-cli which breaks relative paths in file...
Read more >
HAPI Routes - am I missing a module to support more ... - Reddit
I am trying to implement Swagger as I write an API and I cannot seem to follow any tutorials as HAPI is kicking...
Read more >
HTTP Server mocking for Node.js
function startScope(basePath, options) { return new Scope(basePath, options); } ... as a JSON file, you can load them directly through `nock.load(path)`.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found