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

前端 未结 11 1492
佛祖请我去吃肉
佛祖请我去吃肉 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:11

    Had to add the dependencies manually, even when it gave a warning of incompatibility, because the npm-force-resolutions solution did not work for me.

    1. First, I had to add the following dependencies to package.json (dependencies because I'm using create-react-app, which I have never seen to use devDependencies):
    "dependencies": {
      "@typescript-eslint/eslint-plugin": "^4.1.1",
      "@typescript-eslint/parser": "^4.1.1",
    }
    
    1. Then, I do rm -rf node_modules/ so I can have a clean install of npm stuff.

    2. Next, install everything: npm install.

    3. Check that you have the correct version: npm ls @typescript-eslint/eslint-plugin. It said UNMET PEER DEPENDENCY but I had to ignore it because otherwise I could not get this working.

    4. npm start to make sure the create-react-app now works.

    I'd advice going for the npm-force-resolutions solution first, but if it fails try this one.

    Oh, and one extra note:

    This entire disaster was because I did something like this:

    interface SomeInterface {
      someBoolean: boolean,
      someList: number[],
      someTuple: [string, string]  // <-- THIS is the problem
    }
    

    If I removed that commented line, the code would compile without issues. I kept it that way because I had already made my code to work like that, but if you just avoid having a tuple inside the interface (didn't matter if it had labels or not), you can potentially avoid all this hassle.

提交回复
热议问题