Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create react app - without typescript , got Error: Failed to load parser '@typescript-eslint/parser'

I have sample installation of react-app and I got the following

Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc » eslint-config-react-app#overrides[0]': Cannot find module 'typescript' 

after running

 npm run lint -> eslint .

I don't use typescript in this project. I tried to install it from scratch and got it again. also tried to remove tslint from vscode plugin

like image 200
Tuz Avatar asked Feb 09 '20 08:02

Tuz


People also ask

How to add eslintignore to react app?

Create React App adds eslint config to package.json, so you just have to add eslintIgnore with node_modules in package.json. A cleaner alternative to creating a separate file .eslintignore Show activity on this post.

Why is ESLint looking for TypeScript?

Your error message says eslint is looking for typescript because of a setting in the file .eslintrc so try looking in that file for @typescript-eslint/parser and remove it. Show activity on this post.

How do I create a simple react app?

The simplest way to create a basic react app is to run npx create-react-app my-app --template typescript and boom your basic react app will be created but have you ever wondered, can I do that whole process on my own? Well yes, you can. Pre-requisites: Node js and Vs code.

How to check if WebStorm is using TypeScript or not?

The built-in eslint integration in Webstorm runs correctly per-file on all the files but crashes with the same error on my typedefs file. @Kicu The plugin determines whether you're using Typescript or not by searching for *.ts files. You think you're not using ts while in fact you are.


4 Answers

You can add this to your .eslintignore file in the root of your project.

node_modules

create-react-app team will release a new version with that fix also

https://github.com/facebook/create-react-app/pull/8376

like image 134
Tuz Avatar answered Oct 11 '22 03:10

Tuz


Create React App adds eslint config to package.json, so you just have to add eslintIgnore with node_modules in package.json. A cleaner alternative to creating a separate file .eslintignore

  // package.json
  // ...
  "eslintConfig": {
    "extends": "react-app"
  },
  "eslintIgnore": [
    "node_modules",
    "build/*"
  ],
like image 36
Dmitriy Avatar answered Oct 11 '22 02:10

Dmitriy


I had the same issue when trying to create a new react app today.

You can try the following steps:

  1. Make sure you update your nodejs to the latest version
  2. Make sure your folder path is short and does not contain spaces
  3. Run: npm install -g create-react-app
  4. Run: npm i --save-dev typescript @typescript-eslint/parser
  5. Run: create-react-app my-app
like image 28
Mister 3D Avatar answered Oct 11 '22 02:10

Mister 3D


Most likely, you have this in your .eslintrc:

extends: react-app

It means the following rule is applied:

files: ['**/*.ts?(x)'], 
parser: '@typescript-eslint/parser', 

Which probably means you have *.ts/*.tsx files in your root folder. But maybe it's the vscode-eslint. Did you try to run yarn lint from the terminal?

like image 38
Vanuan Avatar answered Oct 11 '22 01:10

Vanuan