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

前端 未结 11 1494
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 18:49

Currently starting up the server on my client side, the error above is what I have been getting. I am using Typescript, React, ESlint. I can\'t seem to go forward since th

相关标签:
11条回答
  • 2020-12-30 19:14

    Sometimes this error is a result of an invalid type as others have stated

    I've gotten this error when using a bare array as a type

    const someVariable: [] //Incorrect
    const someVariable: string[] //Correct
    

    I also got this error when typing an multidimensional array incorrectly:

    const someVariable : [string[]] //Incorrect. Results in map error
    
    const someVariable : string[][] //Correct
    

    The error message from typescript is pretty cryptic so hopefully this helps.

    0 讨论(0)
  • 2020-12-30 19:15

    Yarn users, I had the same problem in react, I solved the problem remove package.json and install again:

    rm -rf node_modules
    yarn cache clean
    yarn install
    

    I'd made with vscode closed by linux terminal, to don't have problem with cache.

    0 讨论(0)
  • 2020-12-30 19:16

    As @mohammadreza berneti mentioned, deleted node_modules/.cache helped in my case (an nothing else needed)

    0 讨论(0)
  • 2020-12-30 19:17

    This is what worked for my CRA project.

    Step 1: edit package.json and set typescript version to ^3.9.7

    Step 2: delete .cache folder in node_modules

    Step 3: run npm install

    0 讨论(0)
  • 2020-12-30 19:18

    Your version of TypeScript is not compatible with your eslint. You can fix it by upgrading these two dependencies to the latest version. Version 4.6.0 is compatible with TypeScript 4.0.5

    "devDependencies": {
      "@typescript-eslint/eslint-plugin": "^4.6.0",
      "@typescript-eslint/parser": "^4.6.0",
    }
    
    0 讨论(0)
提交回复
热议问题