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

2,365 阅读5分钟

原文见 pauledenburg.com/line-0-pars…

报错如下:

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

检查有没有声明为空数组 [ ]的类型!!!

如 type A = [ ],  const B:[ ] = [ ]

如果没有,就重新install.

原文搬运:

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