Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ESLint with Typescript: SyntaxError: Unexpected token '||=' in node_modules folder

I’m trying to use ESLint with a pretty basic typescript project and I’m running into errors with the setup.

Description:

It seems that ESLint is picking up errors in the node_modules folder, despite the fact that this folder should be ignored by default. Here’s the specific error that I’m being shown:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Oops! Something went wrong! :(

ESLint: 8.53.0

/Users/my_name/repo_name/node_modules/@typescript-eslint/scope-manager/dist/referencer/ClassVisitor.js:123
        withMethodDecorators ||=
                             ^^^

SyntaxError: Unexpected token '||='
    at wrapSafe (internal/modules/cjs/loader.js:1029:16)
    at Module._compile (internal/modules/cjs/loader.js:1078:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)
    at Object.<anonymous> (/Users/my_name/repo_name/node_modules/@typescript-eslint/scope-manager/dist/referencer/Referencer.js:20:24)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)

I’ve set up my .eslintrc.json file in the project root following the guidance given in ESLint’s documentation:

eslintrc.json

{
    "parser": "@typescript-eslint/parser",
    "plugins": [
        "@typescript-eslint"
    ],
    "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
    ],
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project": "./tsconfig.json"
    }
}

The required dependencies in my package.json are up to date:

package.json

...
"devDependencies": {
    "@types/express": "^4.17.21",
    "@types/node": "^20.8.10",
    "@typescript-eslint/eslint-plugin": "6.10.0",
    "@typescript-eslint/parser": "6.10.0",
    "eslint": "^8.53.0",
    "typescript": "^5.2.2"
  }
...

I’m specifying ES6 in my tsconfig.json file:

tsconfig.json

{
    "compilerOptions": {
        "outDir": "./dist",
        "target": "ES6",
        "sourceMap": true,
        "noImplicitAny": true,
        "strictNullChecks": false,
    },
    "include": [
        "./**/*"
    ],
    "exclude": [
        "./node_modules/**/*",
        "./dist/**/*"
    ]
}

I thought that I was already specifying to ignore the node_modules and dist folders here but just in case, I’ve added an .eslintignore file in my root and asked again for these to be ignored, but I’m getting the same error regardless.

I’m note sure if it’s an issue caused by node? I’m using version 14.21.3. Can anyone suggest where I am going wrong? This is my first time using ESLint so I may have made a silly mistake somewhere.

>Solution :

The logical or assignment is available from Node15 onwards.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading