31

My React app is not failing to compile due to the error: Definition for rule '@typescript-eslint/consistent-type-assertions' was not found

I'm kind of at a loss. I'm unable to find any current rule definitions in the project. The project was compiling initially. The error started after I restructured the app.

The app is failing to compile with error: Definition for rule '@typescript-eslint/consistent-type-assertions' was not found

packge.json -

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/react-dom": "16.9.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.1.1",
    "styled-components": "^4.3.2",
    "typescript": "^3.5.3"
  },
  "scripts": {
    "start": "PORT=3005 react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --transformIgnorePatterns",
    "e2e": "./node_modules/.bin/cypress open"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/dom": "^6.1.0",
    "@testing-library/jest-dom": "^4.0.1",
    "@testing-library/react": "^9.1.3",
    "@types/jest": "^24.0.18",
    "@types/lodash": "^4.14.137",
    "@types/node": "^12.7.2",
    "@types/react": "^16.9.2",
    "@types/react-router-dom": "^4.3.4",
    "@types/styled-components": "^4.1.18",
    "babel-jest": "^24.9.0",
    "cypress": "^3.4.1"
  }
}
ezagala
  • 311
  • 1
  • 3
  • 5
  • 2
    Facing the same problem after upgrading dependencies – Möhre Sep 20 '19 at 17:02
  • Does this answer your question? [My create-react-app is failing to compile due to ESLint error](https://stackoverflow.com/questions/64518226/my-create-react-app-is-failing-to-compile-due-to-eslint-error) – vsync Nov 11 '21 at 13:13

9 Answers9

14

Just update react-scripts. I solved it by uninstall and install again. In command line:

uninstall:

npm uninstall react-scripts --save

and install again:

npm i react-scripts
tom
  • 9,550
  • 6
  • 30
  • 49
11

When I ran into this, I had created a brand new app using create-react-app my-app --typescript then copied the dependencies from another project that I had just finished. After messing around with things I noticed that the react-scripts was at version 3.1.1, when I finally got this running again the working package.json had it at 3.1.2 looks like this is the culprit. A working package.json would look like:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/jest": "24.0.18",
    "@types/node": "12.7.5",
    "@types/react": "16.9.2",
    "@types/react-dom": "16.9.0",
    "node-sass": "^4.12.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-scripts": "3.1.2",
    "typescript": "3.6.3"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Trying to get the error to disappear was a challenge, there is an evil bug in Visual Studio that will leave your VSCompiler.exe and other services hung up only using the version of the file that it had when the services hung up. No matter what you do nothing will work until you get these restarted, see this answer on some tips how to resolve it, I realize it is for Angular but the same principles apply.

Andy Braham
  • 9,594
  • 4
  • 48
  • 56
7

I found a solution. 1) Delete the node_modules 2) update the Package.Json line of React-scripts to this: ""react-scripts": "3.1.2"" 3) run npm i

This should work

Ariel Volnicher
  • 153
  • 1
  • 1
  • 8
3

yarn add -D @typescript-eslint/eslint-plugin@latest or to be more precise yarn add -D @typescript-eslint/eslint-plugin@^2

I experienced the issue because the plugin was at @typescript-eslint/eslint-plugin@^1.

Mateja Petrovic
  • 3,799
  • 4
  • 25
  • 40
2
  1. In Package.json - Update version of react-scripts to "react-scripts": "3.1.2"
  2. npm install --save
  3. npm start
0

I could solve the problem by running yarn install again. If this doesn't work out, you can try to remove the node_modules folder completely and run yarn install again.

Möhre
  • 929
  • 1
  • 6
  • 17
0

I just discovered this exact error on a create-react-app git repository I cloned. Running npm install followed by npm start gave me the same error message.

I then realised that the creator had been using yarn rather than npm. So I deleted the repo, re-cloned it and ran yarn install followed by yarn start. The error cleared.

This could be a npm vs yarn issue therefore. Especially as create-react-app will default to yarn if you have installed it previously; which might cause issues if you continue to use npm? Appreciate this is a different circumstance as this is your own app, but it might be related.

Admittedly I ran straight into a different error, but at least I had made progress...

Concrete_Buddha
  • 556
  • 4
  • 16
0

I tried all the steps before, however, what actually solved my problem were these steps:

  • 1.- Delete node_modules
  • 2.- delete package-lock.json
  • 3.- Update package.json line of React-scripts like this: "react-scripts": "3.1.2"
  • 4.- npm install (or sudo npm install if you need further authorization).

I hope it helps somebody else.

webtechnelson
  • 330
  • 1
  • 7
  • 13
0

For me, I was supposed to use Yarn but instead I blindly use npm.

  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29943521) – the Tin Man Sep 28 '21 at 19:13