Line 0: Parsing error: Cannot read property 'map' of undefined Line 0: Parsing error: Cannot read property 'map' of undefined typescript typescript

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[]}