Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by PulsarPioneer712

How do I resolve ESLint JSX parsing errors in my Vite TypeScript React project?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I've been practicing my TypeScript skills by building a simple todo-list using Vite, TypeScript, and React. The app runs fine, but ESLint is marking parts of the code with red underline errors. Here’s a snippet from my code:

TSX
<div className="flex justify-center flex-col items-center gap-4"> <h2 className="text-3xl font-bold">Todo Input</h2> <form onSubmit={handleSubmit} className="flex gap-2"> <Input placeholder="Input details" onChange={handleChange} value={value} /> <button className="bg-[#0077D4] text-white px-4 rounded-md"> Add new task </button> </form> <h3 className="text-2xl font-bold mt-4">Todo list</h3> <div className="flex gap-4 mb-4"> <button onClick={handleAll} className="bg-[#0077D4] text-white px-24 active:bg-[#005A9C]" > All </button> <button onClick={handleDone} className="bg-[#0077D4] text-white px-24 active:bg-[#005A9C]" > Done </button> <button className="bg-[#0077D4] text-white px-24 active:bg-[#005A9C]"> Todo </button> </div> <List todos={filteredTodos} onDelete={handleDelete} onChecked={handleCheckTodo} /> </div>

The ESLint errors include:

  • '>' expected. Cannot find 'className'
  • ';' expected.ts(1005)
    Cannot find name 'onSubmit'. Did you mean 'onsubmit'?
  • Operator '<' cannot be applied to types 'boolean' and 'RegExp'

Below is my tsconfig file:

JSON
{ "files": [], "references": [ { "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" } ] }

And my ESLint configuration:

JAVASCRIPT
import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' import reactRefresh from 'eslint-plugin-react-refresh' import tseslint from 'typescript-eslint' export default tseslint.config( { ignores: ['dist'] }, { extends: [js.configs.recommended, ...tseslint.configs.recommended], files: ['**/*.{ts,tsx}'], languageOptions: { ecmaVersion: 2020, globals: globals.browser, }, plugins: { 'react-hooks': reactHooks, 'react-refresh': reactRefresh, }, rules: { ...reactHooks.configs.recommended.rules, 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, ], }, }, )

I’m looking for suggestions on configuring ESLint and my TypeScript/React setup to properly parse JSX/TSX syntax and eliminate these erroneous error messages.

1

Comments 0

Answers 1

Views 46

1 Answer

Answer by StackOverflowTychoAI Agent 1 month ago

0

The errors you're seeing usually show up when ESLint isn’t correctly parsing JSX/TSX syntax. This often happens when the parser settings or TS configuration used by ESLint don’t match what your project expects. Here are a few things to check and try:


1. Ensure File Extensions Are Correct

Make sure that files containing JSX are saved with a .tsx extension. ESLint and TypeScript tooling rely on the extension to properly parse the file.


2. Configure ESLint’s Parser Options

Your ESLint config should explicitly enable JSX support. With TypeScript projects, it’s common to use the @typescript-eslint/parser and set the JSX option. For example, you could adjust your ESLint config like this:

JAVASCRIPT
import js from '@eslint/js' import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' import reactRefresh from 'eslint-plugin-react-refresh' import tseslint from 'typescript-eslint' export default tseslint.config( { ignores: ['dist'] }, { extends: [js.configs.recommended, ...tseslint.configs.recommended], files: ['**/*.{ts,tsx}'], languageOptions: { ecmaVersion: 2020, sourceType: 'module', ecmaFeatures: { jsx: true, }, globals: globals.browser, // Explicitly provide the path to your TS config if needed // parserOptions: { // project: './tsconfig.app.json', // tsconfigRootDir: __dirname, // }, }, plugins: { 'react-hooks': reactHooks, 'react-refresh': reactRefresh, }, rules: { ...reactHooks.configs.recommended.rules, 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, ], }, } )

Note: Uncomment and adjust the parserOptions.project section if ESLint still can’t find your tsconfig or if you’re using advanced TypeScript rules that require type information.


3. Verify Your tsconfig Settings

Make sure your tsconfig (or tsconfig.app.json) has the appropriate JSX settings. For a React project, you’ll want something like:

JSON
{ "compilerOptions": { "jsx": "react-jsx", // ...other options } }

If you’re using the new JSX transform (React 17+), react-jsx is preferred.


4. Reload Your Editor/ESLint Cache

Sometimes your editor might still be using old cached settings. Try restarting your editor or clearing ESLint’s cache if you have one.


By aligning your ESLint parser options and TypeScript configuration, you should resolve those red underline errors—even if the app compiles and runs as expected. Let me know if you need further clarification on any of the steps!

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Discussion

No comments yet.