Line 0: Parsing error: Cannot read property 'map' of undefined
Edit: as noted by Meng-Yuan Huang, this issue no longer occurs in react-scripts@^4.0.1
This error occurs because react-scripts
has a direct dependency on the 2.xx range of @typescript-eslint/parser
and @typescript-eslint/eslint-plugin
.
You can fix this by adding a resolutions field to your package.json
as follows:
"resolutions": {
"**/@typescript-eslint/eslint-plugin": "^4.1.1",
"**/@typescript-eslint/parser": "^4.1.1"
}
NPM users: add the resolutions field above to your package.json
but use npx npm-force-resolutions to update package versions in package-lock.json
.
Yarn users: you don't need to do anything else. See selective dependency resolutions for more info.
NOTE: if you're using a monorepo/Yarn workspaces, the resolutions
field must be in the top-level package.json
.
NOTE: yarn add
and yarn upgrade-interactive
don't respect the resolutions
field and they can generate a yarn.lock
file with incorrect versions as a result. Watch out.
For future Googlers:
I had the same issue just now on TypeScript 4.0.2 in a Vue.js 2 project. I fixed it by upgrading @typescript-eslint/eslint-plugin
and @typescript-eslint/parser
to the latest that npm would give me using @latest
, which at the time was 3.3.0 and 3.10.1, respectively.
Try playing around with variable types inside the interfaces. E. g I've got this error when I had such state interface:
interface State{
foo: []
}
but when I've changed the type of array it worked:
interface State{
foo: string[]
}
Your version of TypeScript is not compatible with your eslint. You can fix it by upgrading these two dependencies to the latest version.
TypeScript 4.0.5 is compatible with version 4.6.0
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.6.0",
"@typescript-eslint/parser": "^4.6.0",
}
TypeScript 4.1.5 is compatible with version 4.18.0
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
}
TypeScript 4.2.4 is compatible with version 4.23.0
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
}
TypeScript 4.3.2 is compatible with version 4.25.0
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
}
TypeScript 4.5.5 is compatible with version 4.25.0
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
}