4

I upgraded my 'react-scripts' to the latest version to get rid of a "'React' used before defined" error. I also upgraded to the latest version of typescript.

Now I'm receiving the following:

Failed to compile.

src\components\NearBy.tsx
Line 26:61:  Parsing error: Unexpected token, expected ","

  24 |     const [customers, setCustomers] = useState<Array<any>>([]);
  25 |     const [activeMenuIdx, setActiveMenuIdx] = useState(0);
> 26 |     const [activeCustomer, setActiveCustomer] = useState({} as ICustomerDetail);
     |                                                             ^
  27 |     const [nearBySettings, setNearBySettings] = useState({} as any);

I thought it might be the cast of an object to an interface, but the following line (27) will generate the same error, when using 'any'.

package.json

{
    "name": "microsoft-teams-ext",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@fluentui/react-northstar": "^0.49.0",
        "@microsoft/teams-js": "^1.6.0",
        "@types/classnames": "^2.2.11",
        "@types/react": "^16.9.53",
        "@types/react-dom": "^16.9.8",
        "@types/react-router-dom": "^5.1.6",
        "@typescript-eslint/eslint-plugin": "^4.6.1",
        "@typescript-eslint/parser": "^4.6.1",
        "bingmaps": "^2.0.3",
        "classnames": "^2.2.6",
        "msteams-react-base-component": "^2.1.0",
        "msteams-ui-styles-core": "^0.8.2",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-router-dom": "^5.1.2",
        "react-scripts": "^4.0.0-next.117",
        "typescript": "^4.0.5",
        "typescript-collections": "^1.3.3",
        "typestyle": "^2.1.0"
    },
    "resolutions": {
        "**/@typescript-eslint/eslint-plugin": "^4.6.1",
        "**/@typescript-eslint/parser": "^4.6.1"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "eject": "react-scripts eject"
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    },
    "msteams": {
        "teamsAppId": "89b9dfb3-98d2-4b90-9926-2ddf8e4a6aad"
    },
    "eslintConfig": {
        "rules": {}
    }
}

tsconfig.json

{
  "compilerOptions": {
    "esModuleInterop": true,
    "jsx": "react",
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true
  },
  "include": [
    "src"
  ]
}
7
  • 1
    At which point do you receive the error? Is it compiler or linter error? I expect it to be the second because TS itself shouldn't have problems with "as". See stackoverflow.com/questions/60547153/… Commented Nov 6, 2020 at 16:05
  • 1
    @EstusFlask The failure messages show after a "Failed to compile" message is output. So I'm assuming it's during compile. (I'm new to this whole NPM world, so forgive my ignorance.) Commented Nov 6, 2020 at 16:17
  • If there's an error, please post it. You likely truncated parts that could give some clues. Commented Nov 6, 2020 at 16:19
  • @EstusFlask All there is, is what's posted in the first output snippet. (Other than the file name that has the problem.) Commented Nov 6, 2020 at 16:22
  • 1
    This is where you can start digging. It can be debugged on your side. Check stackoverflow.com/questions/59752057/… . Commented Nov 6, 2020 at 16:33

1 Answer 1

3

Add the following configuration in package.json:

"eslintConfig": {
   "extends": [
      "react-app",
      "react-app/jest"
   ]
}
Sign up to request clarification or add additional context in comments.

2 Comments

I had this issue after upgrading, and I had assumed it was something like this (I don't keep up to date with JS / TS world). Do you have any idea why this was added to the package.json instead of being the default like before?
Adding this had no effect for me. I'm using VS Code. I'm curious if you have any suggestions at stackoverflow.com/q/67522592/470749 Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.