Search code examples
javascriptreactjscreate-react-appeslintreact-scripts

using optional chaining(?.) with CRA/react-scripts


I am integrating eslint on a pre-existing project. This project is filled with optional chaining syntax. like the one below:

const data = someEntity?.property;

The syntax works on newer version of eslint (^7.5.0). But react-script does not support eslint above version 6.6.0.

I also cannot disable this using //eslint-disable-next-line or anything like that. It just says parsing error as below:

enter image description here

Currently, I am getting parsing errors all over this project because of this. Is there a way I can disable this error and integrate eslint successfully with my CRA app?


Solution

  • You have to add the babel-eslint into your eslint config file as your parser as below:

    {
       "parser": "babel-eslint"
    }