Cannot read property 'loc' of undefined

See original GitHub issue

Tell us about your environment

  • ESLint Version: v7.13.0
  • Node Version: v14.15.1
  • npm Version: 6.14.9

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using? @typescript-eslint/parser Please show your full configuration:

Configuration
{
    "root": true,
    "extends": ["xxx", "xxx", "plugin:jest/recommended"],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 6,
        "ecmaFeatures": {
            "jsx": true
        },
        "project": "./tsconfig.json"
    },
    "env": {
        "browser": true,
        "mocha": true,
        "node": true,
        "jest": true
    },
    "plugins": ["jest"],
    "rules": {
        "indent": ["error", 4, { "SwitchCase": 1 }],
        "@typescript-eslint/no-namespace": "off",
        "@typescript-eslint/ban-ts-ignore": "off",
        "jest/no-commented-out-tests": "off"
    },
    "globals": {
        "jQuery": false,
        "$": false,
    },
    "overrides": [
        {
            "files": ["test/integration/**/*"],
            "rules":{
                "@typescript-eslint/no-require-imports": "off"
            }
        }
    ]
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. type const in ts file , output above error messages

[Error - 6:22:23 PM] ESLint stack trace: [Error - 6:22:23 PM] TypeError: Cannot read property ‘loc’ of undefined Occurred while linting /Users/xxx/xxx/test/unit/xxx/src/core/xxxx/xxx/cell/xxxx.spec.ts:1 at Object.VariableDeclaration [as listener] (/Users/xxxx/xxx/node_modules/eslint/lib/rules/indent.js:1422:69) at /Users/xxx/xxx/node_modules/eslint/lib/rules/indent.js:1634:55 at Array.forEach () at Program:exit (/Users/xxxx/xxx/node_modules/eslint/lib/rules/indent.js:1634:26) at /Users/xxxx/xxxx/node_modules/eslint/lib/linter/safe-emitter.js:45:58 at Array.forEach () at Object.emit (/Users/xxxx/sheet/node_modules/eslint/lib/linter/safe-emitter.js:45:38) at NodeEventGenerator.applySelector (/Users/xxx/xxxx/node_modules/eslint/lib/linter/node-event-generator.js:254:26) at NodeEventGenerator.applySelectors (/Users/xxx/xxx/node_modules/eslint/lib/linter/node-event-generator.js:283:22) at NodeEventGenerator.leaveNode (/Users/xxxx/xxx/node_modules/eslint/lib/linter/node-event-generator.js:306:14)



What did you expect to happen?

What actually happened? Please include the actual, raw output from ESLint.

Are you willing to submit a pull request to fix this bug?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
mdjermanoviccommented, Dec 25, 2020

Hi @zhongzhong0505, thanks for the issue!

Some core rules don’t work well with typescript code. In that case, replacement rules from @typescript-eslint/eslint-plugin should be used instead. You can find more details here:

https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code.

Can you try with @typescript-eslint/indent instead of the core indent rule:

{
  "indent": "off",
  "@typescript-eslint/indent": ["error"]
}
3reactions
ddialarcommented, Apr 20, 2021
{
  "indent": "off",
  "@typescript-eslint/indent": ["error"]
}

I would recommend to include the amount of indents that are wished:

{
  "indent": "off",
  "@typescript-eslint/indent": ["error", 2]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'loc' of undefined while running cypress ...
issue: "Cannot read property 'loc' of undefined" while running test cases . all the first test case are failing because of this issue...
Read more >
ESLint: Cannot read property 'loc' of undefined - Quasar forum
Hi @icetomcat, that error usually comes from having a misconfigured or globally installed ESLint installation. Can you better describe your dev ...
Read more >
eslint: cannot read property 'loc' of undefined occurred whil
ESLint: Cannot read property 'loc' of undefined Occurred while ; 1. // .estlinrc.js ; 2. { ; 3. rules: { ; 4. {...
Read more >
istanbuljs/nyc - Gitter
TypeError : Cannot read property 'start' of undefined at ./node_modules/nyc/node_modules/istanbul-reports/lib/lcovonly/index.js:32:43 at Array.
Read more >
Supressing ESLint LS errors - Language Server Protocol (LSP)
ESLint : Cannot read properties of undefined (reading 'loc') Occurred while linting /home/non/test/index.ts. Please see the 'ESLint' output ...
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