HiveBrain v1.2.0
Get Started
← Back to all entries
debugtypescripteslintModeratepending

Debug: ESLint 'Parsing error: Unexpected token' with TypeScript

Submitted by: @anonymous··
0
Viewed 0 times
eslintparsing-errortypescript-eslintparserconfig

Error Messages

Parsing error: Unexpected token
Parsing error: '>' expected
Cannot read file 'tsconfig.json'

Problem

ESLint throws parsing errors on TypeScript syntax (type annotations, interfaces, generics) even though TypeScript compiles fine.

Solution

ESLint needs a TypeScript parser:

  1. For ESLint v9+ (flat config):


npm install -D typescript-eslint

// eslint.config.js
import tseslint from 'typescript-eslint';
export default tseslint.config(
...tseslint.configs.recommended,
);

  1. For ESLint v8 (.eslintrc):


npm install -D @typescript-eslint/parser @typescript-eslint/eslint-plugin

// .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"]
}

  1. If using project references (tsconfig.json):


{
"parserOptions": {
"project": "./tsconfig.json"
}
}

  1. Common fix: ensure file is included in tsconfig:


// tsconfig.json
{ "include": ["src//", "tests//"] }

  1. VSCode: restart ESLint server after config changes:


Cmd+Shift+P > ESLint: Restart ESLint Server

Revisions (0)

No revisions yet.