0

I got this error when I used question mark after variable in react js

Module parse failed: Unexpected token (25:28) You may need an appropriate loader to handle this file type.

|   console.log(cryptos);
|   useEffect(function () {
>     var filteredData = data?.data.coins.filter(function (item) {
|       return item.name.toLowerCase().includes(searchTerm);      
|     });

Anyone faced this error before?

Drew Reese
  • 165,259
  • 14
  • 153
  • 181

2 Answers2

1

Just check your NodeJS version with the following command.

node --version

As mentioned in the browser compatibility in the Optional chaining documentation, the NodeJS version should be at least 14.0.0.

If your NodeJS version is lower than it, you should upgrade it to use these latest features.

Shri Hari L
  • 4,551
  • 2
  • 6
  • 18
0

?. is an operator named as optional chain operator. It is new in es11. May be it's not updated in react.js , that's why you are getting error

maruf hasan
  • 9
  • 1
  • 2