alfredopacino
alfredopacino

Reputation: 3241

Inexplicable Parsing error: Unexpected token, expected ","

I'm getting this obscure error, I suspect there is some incompatibility between deps.

  Line 11:85:  Parsing error: Unexpected token, expected ","

> 11 | const tracker = new LoggerTracker({ analyticsId: process.env.REACT_APP_ANALYTICS_ID as string});
     |                                                                                     ^

npm list

├── @commitlint/[email protected]
├── @commitlint/[email protected]
├── @pact-foundation/[email protected]
├── @pact-foundation/[email protected]
├── @testing-library/[email protected]
├── @testing-library/[email protected]
├── @testing-library/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @typescript-eslint/[email protected]
├── @typescript-eslint/[email protected]
├── @zonedigital/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

eslint config

module.exports = {
  "extends": [
    "react",
    "plugin:import/typescript"
  ],
  "rules": {
    "arrow-body-style": 0,
    "react/prop-types": 0,
    "@typescript-eslint/no-non-null-assertion": 0,
    "@typescript-eslint/no-explicit-any": 0,
    "@typescript-eslint/explicit-member-accessibility": 0,
    "@typescript-eslint/explicit-function-return-type": 0,
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          "**/*.test.{ts,tsx}",
          "./src/setupTests.ts",
          "./src/store/__mocks__/*",
          "./src/pact/*"
        ],
        "optionalDependencies": false,
        "peerDependencies": false
      }
    ],
    "camelcase": 0
  },
  "settings": {
    "polyfills": [
      "Promise",
      "fetch",
      "Object",
      "Array.from",
      "URLSearchParams",
      "AbortController",
      "Headers"
    ],
    "react": {
      "version": "detect"
    }
  },
  "env": {
    "browser": true,
    "node": true,
  }
}

Update: For documenting the whole process. Following @morganney suggestion, I've added

  "parser": "@typescript-eslint/parser",

in my eslint config. With that I get the error "Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context" which I solved by also adding parserOptions

"parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },

Second update: Now I'm trying to make eslint recognise Jest to get rid of the errors like: "describe is not defined" from eslint. I've tried by adding the env:

"env": {
    "browser": true,
    "node": true,
    "jest": true
  }

and

"plugin:jest-react/recommended"

I'm not sure it is the correct way according to my dependency versions

Upvotes: 0

Views: 686

Answers (1)

morganney
morganney

Reputation: 13580

Your ESLint config is missing the parser value.

"parser": "@typescript-eslint/parser"

From the docs

This is required, or else ESLint will throw errors as it tries to parse TypeScript code as if it were regular JavaScript.

You should probably add a plugin value too.

plugins: ['@typescript-eslint']

Upvotes: 1

Related Questions