'Optional chaining throwing parsing error on install

I am trying to add the ability to perform optional chaining in my project.

When I run npm i, getting following error.

Module build failed (from ./node_modules/eslint-loader/index.js):
Module failed because of a eslint error.
  /Users/name/projects/src/utils/get.js
    12:20  error  Parsing error: Unexpected token

    10 |   }
    11 |
  > 12 |   const some = map?.a?.b;

I added the following just to have some chaining syntax in my file which is causing the issue.

const get = () => props => {

  const map = {
    a: {
      b: null
    }
  }

  // will install fine if I remove this line
  const some = map?.a?.b;

}

This is in a React project (react version 16.14.0)

I have updated the eslint to version 7.5.0

Added the following to the eslintrc.json file.

{
  "parserOptions": {
    "ecmaVersion": 2020
  }
}

Under the .babelrc file added the following.

{
  "plugins": ["@babel/plugin-proposal-optional-chaining"]
}

This is my package.json file to see relevant dependencies.

{
  "scripts": {
      .....
  },
  "dependencies": {
    "css-loader": "2.1.1",
    "lodash": "^4.17.20",
    "moment": "^2.29.1",
    "prop-types": "^15.7.2",
    "react": "^16.14.0",
    "react-helmet-async": "^1.0.4",
    "react-intl": "^2.2.3",
    "react-redux": "^7.0.0",
    "react-router": "^3.0.0",
    "react-swipeable": "5.5.1",
    "redux": "^4.0.0",
    "reselect": "^4.0.0",
  },
  "devDependencies": {
    "@babel/plugin-proposal-optional-chaining": "^7.16.7",
    "@babel/polyfill": "^7.4.4",
    "amex-jest-preset-react": "^5.0.0",
    "eslint": "^7.5.0",
    "react-dom": "^16.14.0",
  },
}

Note that this is not a CRA (create react app).

Could I please get some advice on why I am getting this parsing error? Thanks.

Solutions from related queries not working for me.

eslint - Optional chaining error with vscode

Allow using ?. syntax in eslint

Why do I need "@babel/plugin-proposal-optional-chaining" in my setup using "@babel/preset-env" and "@babel/preset-typescript"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source