Line 0: Parsing error: : Cannot read property ‘map’ of undefined

the error displayed: Cannot read property 'map' of undefined

If you’re using React and typescript, try these few actions:

  1. Reinstall the dependencies: rm -rf node_modules; yarn install
  2. Remove the cache that’s inside the build directory: remove the build directory and restart the node service
  3. This did it for me (and Trat Westerholt) : don’t type your variables/constants as ‘bare’ arrays:

This failed:

// don't do this - a 'bare' array as type
const customers: [] = []

SOLUTION: It was fixed by:

// add a type to the array
const customers: string[] = []

Click Here to Leave a Comment Below

Typescript: Not all constituents of type 'boolean | (() => void)' are callable - Paul Edenburg - 16/09/2020

[…] the return of the array. Having arrays without a specific type gave me this error as wel: Line 0: Parsing error: : Cannot read property ‘map’ of undefined. The solution was to typehint the […]

Reply
Leave a Reply: